我需要能够检索为 Null 或具有绑定用户名的表行。有人可以解释正确的sql语句吗?
$value = $db_site->prepare('SELECT * FROM tablename WHERE user IS NULL AND user = :user');
$value->bindValue(':user', $user, PDO::PARAM_STR);
$value->execute();
如果重要,则通过 for 循环发送检索到的信息。
use OR instead of AND:
SELECT * FROM tablename WHERE user IS NULL OR user = :user
by using AND you are saying that the user column should be null and equal to :user at the same time.
I need to be able to retrieve the table rows that are Null OR have the bound user name.
'SELECT * FROM tablename WHERE user IS NULL AND user = :user'
Do you notice the difference? ;-)