gpt4 book ai didi

php - pdo 准备好的语句不更新

转载 作者:行者123 更新时间:2023-11-29 07:09:10 26 4
gpt4 key购买 nike

这似乎没有更新记录。谁能看出原因?

    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 }

干杯。

编辑:

我不认为它与:

PHP PDO Update prepared statement problemPHP PDO Prepared statement query not updating record

最佳答案

如果您没有收到异常,那么 SQL 查询或 PDO 如何破坏它都没有问题。最可能的原因是参数问题。所以尝试调试它。将您的 ->bindParam 调用替换为:

    $params = array(
':userId' => $this->userId,
':campId' => $this->campaignId,
':messId' => $messId,
':status' => $status,
);
var_dump($params);
$stmt->execute($params);

这可能会给出一个提示。如果失败,请尝试 ? 枚举参数。在任何情况下,在 SQL 中使用原始“字符串值”重新运行相同的查询以进行测试(在您选择的任何查询工具中)。

关于php - pdo 准备好的语句不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5595363/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com