开发者

Zend_Db_Table - Update don't work

开发者 https://www.devze.com 2022-12-23 00:31 出处:网络
The code 开发者_JAVA百科seems not working. // $counter is an instance of Zend_Db_Table_Abstract $counter->update(array(\'hits\' => \'hits+1\'), \'\"id\" = 1\');

The code 开发者_JAVA百科seems not working.

// $counter is an instance of Zend_Db_Table_Abstract
$counter->update(array('hits' => 'hits+1'), '"id" = 1');

I took a look into the DB profiler and find the following query:

UPDATE `downloads` SET `hits` = ? WHERE ("id" = 1)


You need to use an instance of Zend_Db_Expr (an SQL expression) to get this to work (untested):

$counter->update(array('hits' => new Zend_Db_Expr( 'hits+1' ) ), 'id = 1');

... or something similar I believe should work. Report back if it doesn't work, and I'll come up with a tested answer.

UPDATE:
Ok, I tested it, and it works, provided that you loose the quotes around id in the where clause. id shouldn't be interpreted as a literal string but as a column name. Maybe you ment to use backticks in stead? Like so '`id` = 1'. That is the proper way to quote an identifier for MySQL.

0

精彩评论

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