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 will successfully retrieve all foo from the database, where the bar column is null.
However, now I would like to do the opposite. I would like to get all columns where the bar column is not null.
I know that I could just replace bar = :bar with bar IS NOT NULL . However, I would like to avoid this, and instead do it using prepared instructions, because sometimes I have to build a query string dynamically, and there will be a lot of additional work for this manually.
Is it possible?
source share