Thursday, February 10, 2011

How to Set a Value to NULL when using Zend_Db

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?

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

    Gabriel Sosa : I like this method for the _abstraction_ that this method give to you
    From William
  • 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);
    
    From Johrn

0 comments:

Post a Comment