Domanda

Buona giornata!

Sto cercando di eseguire la stessa istruzione di aggiornamento con gli stessi parametri due volte e sembra che non sia eseguito nel secondo caso:

$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!

Non ho abilitato la cache delle query mysql.

Grazie!

È stato utile?

Soluzione

Se UPDATE non modifica alcun dato di fila, MySQL non considera questa riga come interessata:

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

La seconda istruzione UPDATE è stata eseguita ma non ha influito sulle righe dal punto di vista di MySQL , poiché non ha cambiato nulla.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top