Zend: How to insert NULL values into MySQL

Naveed picture Naveed · Nov 13, 2009 · Viewed 9k times · Source

I am using Zend Framework with MySQL,Apache and Ubuntu 9.04.

I am trying to insert NULL values into database like this:

$personObj->setPersonId( '1' );
$personObj->setPersonEmail('NULL');
$personObj->save();

But 'NULL' is stored in database as string and not NULL.

When I use this:

$personObj->setPersonId( '1' );
$personObj->setPersonEmail(NULL);
$personObj->save();

But nothing happens and previous entry is unchanged.

What should I do to insert NULL values into MySQL?

Answer

Joseph Montanez picture Joseph Montanez · Nov 13, 2009

If you are not modifying any of the values after they are assigned then

new $personObj->setPersonEmail(new Zend_Db_Expr('NULL'));