If you echo
(or vardump
or printf
) q1
, for debugging, you would see the actual SQL text being sent to the server.
There's a few problems here. There's a single quote before the paren, we expect that you intend $words
to be array, which is to be converted into a list of string literals in the SQL statement.
IN '(".implode(' , ' , $words). ")"
^ ^^ ^^
It looks like you intended something like this:
IN ('" . implode("','",$words) . "')";
^ ^^ ^^ ^
If $words
is empty, that will result in SQL text:
IN ('')
If $words
contains elements "abc","def"
, that will result in SQL text:
IN ('abc','def')
But again, examine the contents of the actual SQL text before it's sent to the database.
You may want to seriously consider the resulting SQL statement if one of the elements in $words
happens to contain characters that could be interpreted as SQL text, for example:
"abc') OR 1=1; -- "
Classic SQL Injection vulnerability ala Little Bobby Tables http://xkcd.com/327/
SELECT * FROM indexing WHERE keywords IN '(1)
– user3814621 Jul 08 '14 at 02:41