0

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?

Austin Hyde
  • 26,347
  • 28
  • 96
  • 129
  • Could you perhaps show the code that isn't working? – Daniel Egeberg Jun 28 '10 at 14:43
  • possible duplicate of [PHP PDO Prepared statement query not updating record](http://stackoverflow.com/questions/2124294/php-pdo-prepared-statement-query-not-updating-record) – Bill Karwin Jun 28 '10 at 14:45
  • @Bill: It's not. I checked. The problem there was that they were quoting their placeholders. – Austin Hyde Jun 28 '10 at 14:49
  • Solved. My code generates `= NULL` for a WHERE clause, when it should be `IS NULL`. MySQL (for whatever reason) changes `=` to `IS` when it logs it, but not when it executes it. – Austin Hyde Jun 28 '10 at 14:59

1 Answers1

2

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.

Austin Hyde
  • 26,347
  • 28
  • 96
  • 129