views:

35

answers:

2

In MSSQL Server, we make queries for null values like below:

SELECT name, ISNULL(about, ''), contact FROM `user_profile` WHERE userid=1

But when I am trying to do the same with MYSQL then it gives error.

What is the logical and easy way to handle NULL values in php/mysql scenario.

Thanks

+6  A: 

It's IFNULL() for MySQL ^^ But in your case it seems you can return a NULL value, just use a condition to test it.

if(!$result['valuemaybenull']) -> true if 0, false or NULL
MatTheCat
Thanks @Mat, IFNULL will work :)
Prashant
You're welcome ^^ (resolved ?!)
MatTheCat
Yes, its resolved and I am trying to accept it as answer but don't know why SO keep saying "wait for 6 minutes".. will accept it after 6 minutes.. :)
Prashant
^^ I don't know enough yet stackoverflow
MatTheCat
+1  A: 

Be cautios about the following in MySQL:

SELECT 1=NULL returns NULL SELECT 1!=NULL return NULL (as well)

Whenever you want to check for null values use the IS NULL expression (or the above IFNULL)

Slavic