views:

70

answers:

1

The code 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)
+2  A: 

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.

fireeyedboy