mysqlsql-updateincrementzend-db

ZendDb - Increment field with integer - Add +1


I have the following thing: I want to update my table and increment a specific field by 1.

UPDATE my_table SET my_field = my_field + 1 WHERE other_field > 27

How can I achieve this with ZendDB? I'm using Version 1.

This doesn't work:

$ZDB->update("my_table",
      array('my_field' => 'my_field+1'),
      $ZDB->quoteInto("other_field > ?", 27));

Solution

  • Ok, I finally found it! Thanks to this forum link here is my solution:

    $ZDB->update("my_table",
      array('my_field' => new Zend_Db_Expr('my_field+1')),
      $ZDB->quoteInto("other_field > ?", 27));