简体   繁体   中英

PDO Prepared Statement does not UPDATE table

I am developing an ORM based on PDO, for tables that don't have unique ID fields, so when I update or delete, I need to compare to the previous values of the record, and LIMIT 1 .

When my query finally gets to the database and is executed with the parameters, everything is correct, as confirmed by the general query log, however, nothing is happening .

I get no exceptions thrown ( PDO::ERRMODE_EXCEPTION is on), and checking $stmt->errorInfo() comes back clean, but $stmt->rowCount() returns 0 .

As a sanity check, I opened the log file, copy and pasted the UPDATE query right into Sequel Pro (an OSX MySQL GUI) and executed, and everything worked as expected, updating 1 row.

Why does PDO not update the row, when manually executing an IDENTICAL query does?

The problem was that my code generated a query using

WHERE `FieldName` = NULL

when it should have been

WHERE `FieldName` IS NULL

When executed by PDO, it kept the = NULL , causing no records to be matched, but when MySQL logged it, it logged IS NULL , so when I copied/pasted, the query was correct and updated the row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM