PDO 不会运行相同的查询两次吗?

发布于 2024-08-04 13:35:56 字数 558 浏览 2 评论 0原文

再会!

我试图使用相同的参数运行相同的更新语句两次,但在第二种情况下它似乎没有执行:

$update_query = $this->db->connection->prepare('UPDATE `Table SET `field` = :price WHERE (`partnum` = :partnum)');

$update_query->execute(array('price' => 123, 'partnum' => test));
var_dump($update_query->rowCount()); //returns 1

// If I insert here any statement it works as expected

$update_query->execute(array('price' => 123, 'partnum' => test));
var_dump($update_query->rowCount()); //returns 0!

我没有启用 mysql 查询缓存。

谢谢!

Good day!

I'm trying to run the same update statement with the same params twice and it seems that it is not executed in the second case:

$update_query = $this->db->connection->prepare('UPDATE `Table SET `field` = :price WHERE (`partnum` = :partnum)');

$update_query->execute(array('price' => 123, 'partnum' => test));
var_dump($update_query->rowCount()); //returns 1

// If I insert here any statement it works as expected

$update_query->execute(array('price' => 123, 'partnum' => test));
var_dump($update_query->rowCount()); //returns 0!

I do not have mysql query cache enabled.

Thanks!

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

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

发布评论

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

评论(1

大姐,你呐 2024-08-11 13:35:56

如果 UPDATE 没有更改一行中的数据,MySQL 不会将此行计为受影响:

mysql> SELECT val FROM t_source2 WHERE id = 1;
+-----+
| val |
+-----+
|  10 |
+-----+
1 row in set (0.00 sec)

mysql> UPDATE t_source2 SET val = 1 WHERE id = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> UPDATE t_source2 SET val = 1 WHERE id = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

第二个 UPDATE 语句确实执行,但没有影响任何行从MySQL的角度来看,因为它没有改变任何东西。

If UPDATE changes no data in a row, MySQL doesn't count this row as affected:

mysql> SELECT val FROM t_source2 WHERE id = 1;
+-----+
| val |
+-----+
|  10 |
+-----+
1 row in set (0.00 sec)

mysql> UPDATE t_source2 SET val = 1 WHERE id = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> UPDATE t_source2 SET val = 1 WHERE id = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

The second UPDATE statement did execute but affected no rows from MySQL's point of view, since it changed nothing.

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