开发者

Zend Framework MySQL Update Column

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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜