PDOs don't run the same queries twice?

Good day!

I am trying to run the same update statement with the same parameters twice, and it seems to fail 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.

Thanks!

+3
source share
1 answer

If it UPDATEdoes not change any data in a row, MySQLdoes not consider this row:

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 statement UPDATEexecuted, but did not touch the lines from the point MySQL, since it did not change anything.

+6
source

Source: https://habr.com/ru/post/1717354/


All Articles