mysql 的IFNULL失效
PHPz
PHPz 2017-04-17 15:50:46
0
1
671

想要判断当查找的值找不到时给一个默认值,就试试IFNULL函数。
这样是可以查到的select IFNULL(NULL,'null') as name from game
输出结果:


但是当加了查询套件却出不来了:

select  IFNULL(NULL,'null') as name from game where id='sdfsf'

输出结果:

这里的id值是数据库中不存在的id,想要的结果是像第一个查询那样,显示为null

PHPz
PHPz

学习是最好的投资!

reply all(1)
伊谢尔伦

The role of IFNULL() in MySQL:

SELECT IFNULL(x, y)

If x in the returned data recordis not NULL (does not contain 0), IFNULL() returns x, otherwise it returns y.

Because the id value you query does not exist in the database, no record is returned, and IFNULL() will not work either. As for giving a default value when no records are returned, it is recommended to implement it programmatically.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!