views:

602

answers:

2

How would I write this sql the Zend Framwork way?

UPDATE register 
SET balance = (balance + 10) 
WHERE added_date > 1259944184 ;

I can't find any examples of this on Zends website or the web.
Do I need to use "Zend_Db_Expr" ?

thanks

A: 

acording to zend framwork documentation

use this

$data = array(
    'balance'      => 'balance + 10'
);

$n = $db->update('register ', $data, 'added_date > 1259944184');
streetparade
That didn't work for me. I got it working using an sql query like this:$stmt=$this->_db->query(' UPDATE '.$this->_name.' SET balance = (balance + \''.$difference.'\') WHERE added_date > \''.$addedDate.'\' '); $numAdded=$stmt->rowCount(); echo '<br>'.$numAdded.' Rows Affected'; But I really want to use the fluid method of ZF.
EricP
A: 

This worked for me:

$data = array(balance => new Zend_DB_Expr('balance + 10'));

$db->update('register ', $data, 'added_date > 1259944184');
Benedict Cohen