Reputation: 27436
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?
Upvotes: 0
Views: 879
Reputation: 27436
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.
Upvotes: 2