delight-im/PHP-DB

Unable to execute LIKE statements

creativenoobie opened this issue · 3 comments

Hey,

I'm trying to execute following statement:

$exists = $this->db->exec("SHOW COLUMNS FROM table_name LIKE ?", [$column_name] );

It throws a syntax error violation.
While running this statement directly on mysql server, it works with:
SHOW COLUMNS FROM table_name LIKE 'column_name'

I tried executing statement like:
$exists = $this->db->exec("SHOW COLUMNS FROM table_name LIKE '?'", [$column_name] );
(Inserting single quotes around ?), It returns an invalid result, which was not correct, of course.
After a quite, debugging and logs, I found that my statement is executed as:
SHOW COLUMNS FROM table_name LIKE '?'

Is there any execute the statement? It would be of great help!

Thanks in advance!

ocram commented

To be honest, I don’t really know that syntax

SHOW COLUMNS FROM table_name LIKE ?

which you have been using. Perhaps PDO (which this library uses) cannot compile this to a prepared statement. I don’t know.

Try using

SHOW COLUMNS FROM table_name WHERE Field = ?
-- or
SHOW COLUMNS FROM table_name WHERE Field LIKE ?

instead and it should work.

Hope that helps!

Thanks! This works

ocram commented

Great to hear that, thanks!