Search code examples
mysqlzend-frameworkdelete-row

how to delete row in zend framework query?


i need to do a deleting query with limit in zend framework 1

here is my mysql query

DELETE FROM TABLE1
WHERE USER =  '123'
LIMIT 1

this is my zend query

$this->_dbObj->delete('table1', "USER = ?" , 123, "LIMIT ?",1);

but this query seems didn't work. can anybody help? thanks


Solution

  • First of all, your current delete query does not make much sense, because you are using LIMIT 1 without an ORDER BY clause. You should ideally tell MySQL which of the possible matching records you want to delete:

    DELETE FROM TABLE1
    WHERE USER = '123'
    ORDER BY some_col
    LIMIT 1
    

    You may try using quoteInto here:

    $sql = "DELETE FROM TABLE1 WHERE USER = ? ORDER BY some_col LIMIT 1";
    $query = $this->_dbObj->quoteInto($sql, 123);
    $this->_dbObj->query($query);