Jump to content

NULL and single quotes ' '


robert_gsfame

Recommended Posts

I have query like this SELECT * FROM table1 WHERE folder=''

the problem is no result appear when using that query, then i change to folder is NULL and it works..

 

What is the different between those two ??? if i want to have any records where folder is empty then which one should i use NULL or ''???

Link to comment
https://forums.phpfreaks.com/topic/199786-null-and-single-quotes/
Share on other sites

NULL means no value assigned.  '' is an assignment.  You probably want:

 

 

WHERE folder IS NULL OR folder = ''

 

Use NULL where nothing has been assigned to it.  Don't assign '' (although most php I've seen assigns '' when the variable is NULL).  If you want to clear a value use SET folder=NULL.

 

I actually tried to make that coherent.  Essentially what I am trying to say:

 

$sql="UPDATE folder_table SET (folder='$folder')"

 

If $folder=NULL in PHP then SQL is going to set the field as '' because the variable is surrounded by ticks. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.