PHP PDO相关:更新SQL语句未更新数据库内容

发布于 2024-08-24 05:04:28 字数 810 浏览 3 评论 0原文

我试图在 PHP 脚本中使用准备好的语句来实现更新语句,但它似乎它没有更新数据库中的记录,我不确定为什么,所以如果您能分享一些见解,我将不胜感激。

代码

$query = "UPDATE DatTable SET DF_PARTY_ID = :party_id,
          DF_PARTY_CODE = :party_code,
          DF_CONNECTION_ID = :connection_id WHERE DF_PARTY_ID = ':party_id'";
$stmt = $this->connection->prepare($query);
$stmt->bindValue(':party_id', $data[0], PDO::PARAM_INT);
$stmt->bindValue(':party_code', $data[1], PDO::PARAM_INT);
$stmt->bindValue(':connection_id', $data[2], PDO::PARAM_INT);
$stmt->execute();

鼓舞人心导致这种方法的解决方案。我该如何解决这个问题?

I am trying to implement an update statement using a prepared statement in a PHP script, but it appears that it is not updating the record in the database and I am not sure why and so would appreciate if you can share some insights.

Code

$query = "UPDATE DatTable SET DF_PARTY_ID = :party_id,
          DF_PARTY_CODE = :party_code,
          DF_CONNECTION_ID = :connection_id WHERE DF_PARTY_ID = ':party_id'";
$stmt = $this->connection->prepare($query);
$stmt->bindValue(':party_id', $data[0], PDO::PARAM_INT);
$stmt->bindValue(':party_code', $data[1], PDO::PARAM_INT);
$stmt->bindValue(':connection_id', $data[2], PDO::PARAM_INT);
$stmt->execute();

Inspiring solution leading to this approach. How can I fix this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

别把无礼当个性 2024-08-31 05:04:28

可能没有帮助,但是为什么你只绑定 3 个变量,而有 4 个变量呢?我不能说我有在 PHP 中执行此操作的经验,但在 Perl 和 Oracle 中它会抛出错误。我会尝试绑定 2 个 SET 和 1 个 WHERE,然后删除第一个分配,看看是否有效。

Might not help, but why are you only binding 3 variables, when there are 4? I can't say that I have experience doing this in PHP, but in Perl and Oracle it would throw an error. I'd try binding the 2 SETs and the 1 WHERE, and removing the first assignment, and see if that works.

浊酒尽余欢 2024-08-31 05:04:28

确保您尝试更新的 party_id 存在于数据库中。

另外,如果您的表是 InnoDB,请确保您已启用 autocommit 或在更新后发出显式提交。

Make sure that the party_id you are trying to update exists in the database.

Also, if your table is InnoDB, make sure that you have autocommit on or issue an explicit commit after the update is made.

萝莉病 2024-08-31 05:04:28

我不确定你是否想做你想做的事。

您的 UPDATE 语句基本上表示根据 NEW 值更新键和两个值,因为 party_id 位于 SET 和 WHERE 子句中。

您可能需要将准备好的语句更改为:

UPDATE DatTable SET DF_PARTY_ID = :party_id,
DF_PARTY_CODE = :派对代码,
DF_CONNECTION_ID = :connection_id
WHERE DF_PARTY_ID = ':old_party_id'

将新的 party_id 值绑定到 :party_id 并将当前值绑定到 :old_party_id

I'm not sure if you want to do what you're trying to do.

Your UPDATE statement basically says update the key and two values based on the NEW value, since party_id is in the SET and WHERE clauses.

You may want to change your prepared statement to this:

UPDATE DatTable SET DF_PARTY_ID = :party_id,
DF_PARTY_CODE = :party_code,
DF_CONNECTION_ID = :connection_id
WHERE DF_PARTY_ID = ':old_party_id'

bind your NEW party_id value to :party_id and the CURRENT one to :old_party_id

撩动你心 2024-08-31 05:04:28

必须实现基本的错误处理,而不是猜测:

$arr = $stmt->errorInfo();
print_r($arr);

Instead of guessing, basic error handling must be implemented:

$arr = $stmt->errorInfo();
print_r($arr);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文