I have a function that I call sqlf (), it emulates prepared statements. For example, I can do things like:
$ sql = sqlf ("SELECT * FROM Users WHERE name =: 1 AND email =: 2", 'Big "John"', ' bj@example.com ');
For various reasons, I cannot use the prepared instructions, but I would like to imitate them. The problem I am facing is with queries like
$ sql = sqlf ("SELECT * FROM Users WHERE id IN (: 1)", array (1,2,3));
My code works, but it fails with an empty array, for example. The following causes the mysql error:
SELECT * FROM Users WHERE id IN ();
Does anyone have any suggestions? How should I translate and empty an array in sql that can be entered into an IN clause? NULL substitution will not work.
source share