Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend: How to insert NULL values into MySQL

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?

like image 952
Naveed Avatar asked Nov 13 '09 06:11

Naveed


2 Answers

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

new $personObj->setPersonEmail(new Zend_Db_Expr('NULL'));
like image 196
Joseph Montanez Avatar answered Sep 22 '22 11:09

Joseph Montanez


First thought would be straight passing in the null keyword, without quotes around it. As pavium said, the quotes around it turn it into a string.

like image 43
Tarka Avatar answered Sep 19 '22 11:09

Tarka