Tuesday, February 19, 2019

PHP "SHOW TABLES" MySQLi query not working

You cannot concatenate like that in mySQL, or any form of SQL I can think of.




SHOW TABLES LIKE ?_?_?


Should be:



SHOW TABLES LIKE CONCAT(?, '_', ?, '_', ?) --this gives an error, see below


And I fully agree with @your-common-sense's commentary that this is a terrible way to design a database and you will come to regret it in more ways than just this one messed up query.




edit:



MySQL does not seem to allow functions in a SHOW TABLES statement, so either you'll have to concatenate the table name to a single string in PHP, or you can use a query like:



SELECT 
TABLE_NAME
FROM
INFORMATION_SCHEMA.TABLES
WHERE
table_schema = 'mydb' AND

table_name LIKE CONCAT(?, '_', ?, '_', ?);

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...