I recently found out that you can bind null values in PDO:
$stmt = $db->prepare('SELECT * FROM foo WHERE bar = :bar'); $stmt->execute(array(':bar'=>null)); $foo = $stmt->fetchAll(PDO::FETCH_OBJ); This would successfully fetch all foo from the database, where the bar column is null.
However, I would now like to do the opposite. I would like to fetch all columns where the bar column is not null.
I am aware I could simply replace bar = :bar with bar IS NOT NULL. However, I would like to avoid that, and instead do it through prepared statements, because I sometimes have to build the query string dynamically and having to do it manually would be a lot of extra work.
Is this possible?
IS NOT NULL. PDO will quote the parameters.