PDO 准备好的语句不更新

发布于 2024-10-31 08:10:28 字数 2056 浏览 0 评论 0原文

这似乎没有更新记录。谁能明白为什么吗?

    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 更新准备好的语句问题< /a> 或 PHP PDO 准备好的语句查询不更新记录

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情归归情 2024-11-07 08:10:28

如果您没有收到异常,则说明 SQL 查询或 PDO 对其进行破坏的方式没有任何问题。最可能的原因是参数问题。所以尝试调试一下。将您的 ->bindParam 调用替换为:

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

这可能会给出提示。如果失败,请尝试 ? 枚举参数。无论如何,请在 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:

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

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).

冷清清 2024-11-07 08:10:28

您的查询有问题!使用“,”而不是“AND”:

$stmt = $this->dbh->prepare("UPDATE tbl_inbound_responses SET status = :status, sent = 1 WHERE fk_userId = :userId, fk_campaignId = :campId, pk_messageId = :messId") or die("Prepare Error");

problem in your query ! use "," instead of "AND" :

$stmt = $this->dbh->prepare("UPDATE tbl_inbound_responses SET status = :status, sent = 1 WHERE fk_userId = :userId, fk_campaignId = :campId, pk_messageId = :messId") or die("Prepare Error");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文