PDO and NOT NULL Function

I am new to PDO, and I was wondering if there was an equivalent to the mysql statement that checks if a parameter is non-zero, like this:

SELECT * FROM table
WHERE param IS NOT NULL

I tried this:

$pdo->prepare('SELECT * FROM ' . $tablename . ' WHERE ' . $field . ' = :' . $field . 'AND param IS NOT NULL');

without any success. I also looked on the Internet, but did not find anything suitable, can anyone help?

+3
source share
2 answers

You can use any query in pdo that you can use directly in mysql, but your way to do this is to defeat the goal of using PDO in the first place, you should talk about the query as

$q = $pdo->prepare("SELECT * FROM $tablename WHERE field = :field AND param IS NOT NULL");
$q->execute(array('field' => $field));
+2
source

Is ...

$sql = "SELECT * FROM `tablename` WHERE :field IS NOT NULL";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':field', $field);

... What are you looking for?

-1
source

Source: https://habr.com/ru/post/1670803/


All Articles