note 60723 deleted from language.types.null by danbrown
| From: | danbrown@php.net | Date: | Tue, 19 May 2009 14:20:15 +0000 |
| Subject: | note 60723 deleted from language.types.null by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155737@lists.php.net to get a copy of this message | ||
Note Submitter: zola at zolaweb dot com
----
Discovered something probably worth mentioning.
I had a form that had several values that didn't have to be set. I wanted to use the word
"NULL" as a word (as opposed to the NULL constant) to go into the SQL statement when
creating a new record.
If I do a check based on the variable having no value:
if ($array['var'] == "")
{
$array['var'] = "NULL";
}
Then $array['var'] contains the word "NULL" the way I want it to, BUT I have to
be careful with the sql statement (more on this in a moment)
On the other hand, if I check via !isset()
if (!isset($array['var']))
{
$array['var'] = "NULL";
}
It treats NULL as the constant and unsets the variable.
In the SQL, if I am inserting and put it in as is:
$sql = "INSERT INTO mytable VALUES(NULL, ".$array['var'] .", '
".$array['some_other_var'] ." ')";
the word NULL replaces $array['var'] as it should, but if I enclose the variable in single
quotes (because maybe that variable, if it's set, will contain a space)
$sql = "INSERT INTO mytable VALUES(NULL, ' ".$array['var'] ." ',
' ".$array['some_other_var'] ." ')";
again, it treats NULL as the constant NULL instead of the word.
This seems inconsistent--one would have thought that enclosing it in double quotes would say I want
the letters NULL as opposed to the constant, and I'll bug report it as well but wanted to
mention it here for other users.