2

How would I write this SQL the Zend Framework way?

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

I can't find any examples of this on Zend's website or the web.

Do I need to use "Zend_Db_Expr"?

4 Answers 4

3

This worked for me:

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

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

acording to zend framwork documentation

use this

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

$n = $db->update('register ', $data, 'added_date > 1259944184');
1
  • 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
    Dec 4, 2009 at 22:18
1

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

0

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}");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.