Zend Framework SQL update query
How would I write this SQL the Zend Framework way?
UPDATE register
SET balance = (balance + 10)
WHERE added_date > 12599441开发者_运维知识库84 ;
I can't find any examples of this on Zend's website or the web.
Do I need to use "Zend_Db_Expr
"?
This worked for me:
$data = array(balance => new Zend_DB_Expr('balance + 10'));
$db->update('register ', $data, 'added_date > 1259944184');
acording to zend framwork documentation
use this
$data = array(
'balance' => 'balance + 10'
);
$n = $db->update('register ', $data, 'added_date > 1259944184');
Try this... make sure your model is ready.
$table = new register();
This is the model class
balance=balance+10;
$data = array(
'balance' => 'balance'
);
$where = $table->getAdapter()->quoteInto('added_date > '. 1259944184 );
You can use $where[] for multiple conditions
$table->update($data, $where);
For more details follow link
I used this to modify element order to top. Code as follow from the table class extending Zend_Db_Table_Abstract:
$data = array('i_order' => new Zend_DB_Expr('i_order + 1'));
return $this->getAdapter()->update($this->_name, $data, "i_id != {$oCurrent->i_id} AND i_order < {$i_order}");
精彩评论