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');
Sign up to request clarification or add additional context in comments.

Comments

1

acording to zend framwork documentation

use this

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

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

1 Comment

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.
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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.