【发布时间】:2021-12-25 07:30:51
【问题描述】:
我的 php 中有逻辑可以根据定义的类自动构建更新/插入查询。 它正在生成以下 sql/params: sql:
UPDATE `sessions` SET
`date`=:date,
`client`=:client,
`rate`=:rate,
`notes`=:notes,
`location`=:location,
`includedimagecount`=:includedimagecount,
`paid`=:paid,
`includedimagesdownloaded`=:includedimagesdownloaded,
`additionalpaid`=:additionalpaid,
`additionalimageprice`=:additionalimageprice,
`readyforclient`=:readyforclient,
`additionalimagesdownloaded`=:additionalimagesdownloaded
WHERE uid=:_id_
参数:
[date:"2021-11-22 22:34:00",
client:"D3036CCD-D3C1-44B0-B729-B9B7D72769D9",
rate:"85",
notes:"",
location:"nowhere",
includedimagecount:"10",
paid:1,
includedimagesdownloaded:1,
additionalpaid:0,
additionalimageprice:"4",
readyforclient:1,
additionalimagesdownloaded:0,
_id_:"F23E8D6B-2ED7-4F7A-B59B-42CBDD7B4A5B"]
由于某种原因,我无法弄清楚,在此运行之后 - 我的数据库将列 additionalPaid 和 AdditionalImagesDownloaded 显示为 1,即使这些值在更新参数中显然是 0。
如果有帮助,这里是表的架构...
CREATE TABLE IF NOT EXISTS `sessions` (
`Uid` varchar(36) NOT NULL,
`Date` datetime DEFAULT NULL,
`Client` varchar(36) NOT NULL,
`Rate` float NOT NULL,
`Notes` text,
`Location` varchar(256) DEFAULT NULL,
`IncludedImageCount` smallint NOT NULL DEFAULT '10',
`AdditionalImagePrice` float NOT NULL DEFAULT '4',
`Paid` bit(1) DEFAULT b'0',
`IncludedImagesDownloaded` bit(1) DEFAULT b'0',
`AdditionalPaid` bit(1) DEFAULT b'0',
`ReadyForClient` bit(1) DEFAULT b'0',
`AdditionalImagesDownloaded` bit(1) DEFAULT b'0',
PRIMARY KEY (`Uid`),
UNIQUE KEY `sessions_uid_uindex` (`Uid`),
KEY `sessions_client_fk` (`Client`)
当我直接在 datagrip 中运行相同的查询(仍然使用值占位符)时,它按预期工作。
编辑
我可以通过发送一个较小的对象来解决这个问题,only 是我真正想要更新的列(和 id)。但这是一个开源框架,我需要确保此功能按预期工作。
编辑 2
Here is the code 有问题。 传入的对象是一个类的实例,在属性/表列上具有 1 对 1 匹配。
编辑 3
我也尝试在参数数组中使用:(以匹配查询),并得到相同的结果。
【问题讨论】:
-
我们可能需要查看 PHP 代码来回答您的问题。
-
当然,现在添加问题的链接!
标签: php mysql pdo prepared-statement