8

Is there any way to do what the following code does, using Zend_Db_Table_Abstract?

UPDATE table SET value=value+1 WHERE value < 10;

I tried something like:

$tableModel->update(array('value=value+1'),'value<10');

but no success.

I could fetch the data in a SELECT and then just add 1 to that, but that's no option, cause it's very slow.

1 Answer 1

11

The first argument array is an associative mapping of columns and values. If you're not using an absolute value, i.e. you want to use an expression or function, you need to use Zend_Db_Expr. The following should increment the 'value' column of any rows with a current value under 10.

$tableModel->update(array(
    'value' => new Zend_Db_Expr('value + 1')
), 'value < 10');
Sign up to request clarification or add additional context in comments.

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.