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
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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.