开发者

How to handle NULL values in mysql/php?

开发者 https://www.devze.com 2023-01-19 14:05 出处:网络
In MSSQL Server, we make queries for null values like below: SELECT name, ISNULL(about, \'\'), contact FROM `user_profile` WHERE userid=1

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开发者_StackOverflow社区 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


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


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消