views:

239

answers:

2

When performing UPDATE and INSERT queries using Zend_Db, I frequently need to set values equal to NULL (not ''). However, the default behavior of Zend_Db::insert() and Zend_Db::update() seems to be that values that are empty are translated into empty strings ('') and put into the database as such.

Does anyone know of way to actually force a NULL value to go into fields if the value is empty in php?

+3  A: 

Try setting the affected fields to: new Zend_Db_Expr('NULL')

William
I like this method for the _abstraction_ that this method give to you
Gabriel Sosa
+1  A: 

I've always just been able to do this using PHP's null:

$toUpdate = array('nullValue' => null, 'otherValue' => 'something');
Zend_Db::update($table, $toUpdate, $where);
Johrn