For work related programming I use Zend Framework. I do a lot of database related stuff and for the longest time was using a method for building SQL that was less than desirable. It basically boiled down to using straight up SQL code instead of leveraging the objects and methods provided by the Zend_Db class.

I have switched most of the code over to use the Zend_Db classes, but one SQL query in particular was bugging me. I planned on using the update</em> method of the database object, but the SQL had the following in it "column = column + 1". The where</em> method requires that you specify a WHERE clause, but my WHERE clause was being determined by the database at run time; not pre-calculated.

The solution is to use the Zend_Db_Expr object.

Where normally I would say

$data = array(
'column' => 'new value'
);
</pre>

Instead, you do

$data = array(
'column' => new Zend_Db_Expr('column + 1')
);
</pre>