ZF-6894: Incompatibile Zend_Db::delete() behavior when string array key is used in where condition
Description
There is an unexpected behavior / critical incompatibility using delete method of Zend_Db. When parameter $where is an array('article_id' => 'article_id=123') whole table is emptied instead of deleting a single record with an article_id=123.
Example:
$where = array('article_id' => 'article_id=123'); $this->db->delete('MY_TABLE', $where);
ZF 1.7.8: row with article_id=123 is deleted ZF 1.8.2: result: MY_TABLE is emptied
The behavior is caused by the 'string' array key. If numeric key is used the problem is avoid.
Comments
Posted by Florent Cailhol (ooflorent) on 2009-06-11T03:35:47.000+0000
In Zend/Db/Adapter/Abstract.php on line 659 you can see this: $term = $this->quoteInto($cond, $term);
Using array('article_id' => 'article_id=123') will cause a where query like "WHERE article_id" without any binding. The correct array binding should be array('article_id = ?' => 123).
In my opinion, if the ZF developer team changes this behavior in order to preverse BC, it will introduce unpredictable results.
Posted by Ryan Mauger (bittarman) on 2010-11-20T05:43:42.000+0000
Closing as not an issue, as noted above, the correct and documented notation would be array('field = ?' => $value)