-1

How to write MySQL syntax correctly, if WHERE clause contains bound parameters, and bound parameters can be either NULL or have some value?

$SQL = "SELECT * FROM tabel
WHERE name = :name AND
family = :family AND
midname = :midname";

It works only if bound parameters aren't NULL. Should I write separate statements in case parameters are NULL?

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • You need two Statements. because you can not check `= null`. The check is `is null` – Jens May 29 '17 at 08:54

1 Answers1

0

I think you'd need to write a seperate statement for that, seeing that checking for NULL in MySQL is done using IS NULL and not using = NULL

Next to that, PDO prepared statements considers every parameter to be data, and IS NULL or NULL itself is MySQL value, and not data

Jelmergu
  • 973
  • 1
  • 7
  • 19