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.
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With