在MySQL中增加一列

edw*_*osh 1 mysql zend-framework increment zend-db-table

Zend中有一种方法可以将MySQL列中保存的整数递增1吗?

谢谢

编辑:

我目前的代码如下:

$row = $this->find($imageId)->current();
$row->votes = // THIS IS WHERE I WANT TO SAY INCREMENT
$row->save();
Run Code Online (Sandbox Code Playgroud)

RDL*_*RDL 17

就在这里.以下是使用产品和递增数量字段的示例:

$table     = 'products'; 
$data      = array('prd_qnty' => new Zend_Db_Expr('prd_qnty + 1')); 
$where[] = $db->quoteInto('pr_id = ?', $this->pr_id); 
$db->update($table, $data, $where);
Run Code Online (Sandbox Code Playgroud)


小智 5

投票++不能防止其他请求中的竞争条件,这就是为什么需要拥有数据库解决方案的原因.

例如:想象两个请求几乎同时进入

1st request loads object - votes is 500
2nd request loads object - votes is 500
1st increments value in memory - votes is 501
2nd increments value in memory - votes is 501
1st saves to db - votes is 501
2nd saves to db - votes is 501 (should be 502)
Run Code Online (Sandbox Code Playgroud)