Example of removing multiple conditions using the Zend frame

Can someone give me an example of how to delete a row in mysql using the Zend framework when I have two conditions?

ie: (trying to do this)

"DELETE FROM messages WHERE message_id = 1 AND user_id = 2" 

My code (it looks unsuccessful like that)

 // is this our message? $condition = array( 'message_id = ' => $messageId, 'profile_id = ' => $userId ); $n = $db->delete('messages', $condition); 
+6
php mysql zend-framework zend-db
source share
3 answers

Instead of an associative array, you just need to pass an array of criteria expressions, ala:

 $condition = array( 'message_id = ' . $messageId, 'profile_id = ' . $userId ); 

(and make sure you select these values ​​appropriately if they come from user input)

+8
source share

Better use this:

 $condition = array( 'message_id = ?' => $messageId, 'profile_id = ?' => $userId ); 

Placeholders (?) Are replaced with values, special characters are output, and quotation marks are applied to them.

+29
source share

Use this, it works ...

 $data = array( 'bannerimage'=>$bannerimage ); $where = $table->getAdapter()->quoteInto('id = ?', 5); $table->update($data, $where); 
-3
source share

All Articles