views:

38

answers:

2

I'm trying to delete a Row, can anyone tell me the proper syntax for this ?

class Application_Model_Event extends Zend_Db_Table_Abstract {

    protected $_name = 'xx';
    protected $_primary = 'xx';

   public function deleteEvent ( $xx) {

        $this->delete( $this->select()->where('idEvent = ?', '8'));

    }
}
+3  A: 

No, the delete() function just takes a WHERE condition.

$this->delete("idEvent=8");

Unfortunately, the method doesn't understand the two-argument form like Select objects do. So if you want to interpolate variables into it, you have to do it in two steps:

$where = $this->getAdapter()->quoteInto("idEvent = ?", 8);
$this->delete($where);
Bill Karwin
Yeah its weird.. I ended up just doing raw SQL... Cheated the Model..$db = Zend_Registry::get("db");$db->query('DELETE FROM element WHERE idaForm = '.$idaEvent);
Are you aware that the Db Adapter class has a method `delete($tableName, $whereExpression)`?
Bill Karwin
+3  A: 

To delete row with idEvent value of 8:

$this->delete(Array("idEvent = ?" => 8));

It will do all the proper quoting and sanitising of the values without needing to use the extra quoteInto statement.

Valorin
+1 I forgot about this usage.
Bill Karwin
Yeah, it is a bit obscure and isn't mentioned in the manual (last time I went looking)... I found out by reading the ZF source code.
Valorin