0

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

2 Answers 2

8

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
Sign up to request clarification or add additional context in comments.

2 Comments

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.. :)
^^ I don't know enough yet stackoverflow
1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.