PDO 准备好的语句不更新
这似乎没有更新记录。谁能明白为什么吗?
try {
$status = 'OK';
$messId = 179981;
#die(var_dump($messId, $this->campaignId, $this->userId, $status));
$stmt = $this->dbh->prepare("UPDATE tbl_inbound_responses SET status = :status, sent = '1' WHERE fk_userId = :userId AND fk_campaignId = :campId AND pk_messageId = :messId") or die("Prepare Error");
$stmt->bindParam(':userId', $this->userId);
$stmt->bindParam(':campId', $this->campaignId);
$stmt->bindParam(':messId', $messId);
$stmt->bindParam(':status', $status);
$stmt->execute();
#var_dump($stmt->debugDumpParams(), $stmt->errorInfo());
if($err = $stmt->errorInfo()) {
if($err[0] != '00000') {
var_dump($stmt->debugDumpParams());
}
}
}
catch(PDOException $e) {
die($e->getMessage());
}
剧本也有
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
设定和
$stmt->debugDumpParams();
报告:
SQL: [120] UPDATE tbl_inbound_responses SET status = :status, sent = '1' WHERE fk_userId = :userId AND fk_campaignId = :campId AND pk_messageId = :messId
Params: 4
Key: Name: [7] :userId paramno=-1 name=[7] ":userId" is_param=1 param_type=2
Key: Name: [7] :campId paramno=-1 name=[7] ":campId" is_param=1 param_type=2
Key: Name: [7] :messId paramno=-1 name=[7] ":messId" is_param=1 param_type=2
Key: Name: [7] :status paramno=-1 name=[7] ":status" is_param=1 param_type=2
NULL array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL }
干杯。
编辑:
我不相信它与:
This doesnt seem to update the record. Can anyone see why?
try {
$status = 'OK';
$messId = 179981;
#die(var_dump($messId, $this->campaignId, $this->userId, $status));
$stmt = $this->dbh->prepare("UPDATE tbl_inbound_responses SET status = :status, sent = '1' WHERE fk_userId = :userId AND fk_campaignId = :campId AND pk_messageId = :messId") or die("Prepare Error");
$stmt->bindParam(':userId', $this->userId);
$stmt->bindParam(':campId', $this->campaignId);
$stmt->bindParam(':messId', $messId);
$stmt->bindParam(':status', $status);
$stmt->execute();
#var_dump($stmt->debugDumpParams(), $stmt->errorInfo());
if($err = $stmt->errorInfo()) {
if($err[0] != '00000') {
var_dump($stmt->debugDumpParams());
}
}
}
catch(PDOException $e) {
die($e->getMessage());
}
The script also has
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
set and
$stmt->debugDumpParams();
Reports:
SQL: [120] UPDATE tbl_inbound_responses SET status = :status, sent = '1' WHERE fk_userId = :userId AND fk_campaignId = :campId AND pk_messageId = :messId
Params: 4
Key: Name: [7] :userId paramno=-1 name=[7] ":userId" is_param=1 param_type=2
Key: Name: [7] :campId paramno=-1 name=[7] ":campId" is_param=1 param_type=2
Key: Name: [7] :messId paramno=-1 name=[7] ":messId" is_param=1 param_type=2
Key: Name: [7] :status paramno=-1 name=[7] ":status" is_param=1 param_type=2
NULL array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL }
Cheers.
EDIT:
I don't believe it is the same as:
PHP PDO Update prepared statement problem or PHP PDO Prepared statement query not updating record
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您没有收到异常,则说明 SQL 查询或 PDO 对其进行破坏的方式没有任何问题。最可能的原因是参数问题。所以尝试调试一下。将您的
->bindParam
调用替换为:这可能会给出提示。如果失败,请尝试
?
枚举参数。无论如何,请在 SQL 中使用原始“字符串值”重新运行相同的查询以进行测试(在您选择的任何查询工具中)。If you don't receive an exception, then there's nothing wrong with the SQL query or how PDO mangled it. The most likely cause are problems with the parameters. So try to debug it. Replace your
->bindParam
calls with just:This might give a hint. If it fails, try
?
enumerated params. In any case, rerun the same query with raw 'string values' in the SQL for testing (in any query tool of your choosing).您的查询有问题!使用“,”而不是“AND”:
problem in your query ! use "," instead of "AND" :