简体   繁体   中英

Zend Framework DB delete method strips values

Im trying to delete record from database depending where conditions. The query is pretty simple, but still Im getting strange results. What Im trying to do in ZF:

$where = array(
               $db->quoteInto('name = ?', $name),
               $db->quoteInto('surname = ?', $surname)
         );

$db->delete('users', $where);

While trying to debug Im getting:

DELETE FROM `users` WHERE (name = 'John') AND (surname = 'Johnson')

What is correct and working SQL statement. But later my values are getting stripped, so Im getting query like this:

DELETE FROM `users` WHERE (name = ) AND (surname = )

Depending debug results this happens in Zend_Db_Statement class (Statement.php), _stripQuoted method.

So finally as a result instead of one record deleted Im getting whole table cleared.

I've red the documentation and also Google'd for examples which are pretty much close to my situation. So Im not getting what is wrong with that?

Zend Framework version: 1.12

Any ideas?

The second parameter for delete should be a string. So I think you want:

$where = $db->quoteInto('name = ?', $name).' AND '.$db->quoteInto('surname = ?', $surname);    
$db->delete('users', $where);

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