ZF-3389: Zend_Db_Adapter_Pdo_Mysql::_quote() (possibly others) improperly handles null values.
Description
Zend_Db_Adapter_Pdo_Abstract::_quote(NULL) returns an empty string instead of the unquoted string NULL.
This is important when inserting/updating data in a column that allows NULLs. Its especially important when the column is part of a foreign key relation and inserting an empty string instead of NULL results in a SQL error. Other adapters may be affected by this as well, I only use PDO_MYSQL.
A fix is to insert the following code into the Zend_Db_Adapter_Pdo_Abstract class:
protected function _quote($value) { if ($value === NULL) { return 'NULL'; } return parent::_quote($value); }
Comments
Posted by David Rogers (al_the_x) on 2008-06-11T13:35:27.000+0000
Actually, the proposed solution is insufficient to fix this problem as this will still generate an invalid query:
(
field= NULL) ≠ (fieldIS NULL)At least in MySQL > 5.1.x, I can attest. In our projects we have overridden the WHERE clause builder in Zend_Db_Table_Abstract to produce the correct query strings for set values, such that PHP's NULL value produces SQL's "IS NULL" expression, PHP arrays produce SQL "IN()" expressions, etc.
Posted by Ralph Schindler (ralph) on 2009-12-21T12:59:57.000+0000
I am not sure how we'd go about fixing this, you are making the assumption that the database driver contextually understand what you mean by _quote(null).
Perhaps this is a "Won't Fix"?
Posted by Ralph Schindler (ralph) on 2011-02-17T15:27:29.000+0000
Will attempt to address this API inconsistency in ZF2