Example of a Multi Condition Delete with Zend framework

MichaelICE picture MichaelICE · May 22, 2009 · Viewed 9.9k times · Source

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

i.e: (trying to do this)

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

My code (that is failing miserably looks like this)

// is this our message?
$condition = array(
                   'message_id = ' => $messageId,
                   'profile_id = ' => $userId
);

$n = $db->delete('messages', $condition);

Answer

robbie picture robbie · Jul 31, 2010

Better to use this:

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

The placeholder symbols (?) get substituted with the values, escapes special characters, and applies quotes around it.