0

Lets say I have a general DB class with a query method that is used all over my source code and I want to find out table names that are used in my mysql queries.

The limitation is that I'm using MySql 5.5.36.

Also lets assume that we are talking about millions of tables that I'm using and that using the mysql information schema is not going to happen.

What I would like to know is there an easy way to get table names used?

Explain is obviously good for SELECT statments but since its MySql 5.5.36 I can't use it on replace,update,insert etc.

PDOStatement::getColumnMeta might help us with getting a table name, but it won't work with the queries that return result set.

Some kind of regexp for this might might be possible but I very much doubt that is a good solution for this, my queries are big have multiple JOINS etc. the regexp would be very complicated and probably fail fair percentage of time.

Any other ideas?

4
  • SHOW TABLES;? How are table names fed to the DB class? Dec 4, 2014 at 23:45
  • Lets say they are completly raw sql. So something akin to $db->query('select * from randomtablename;'); Dec 4, 2014 at 23:56
  • Have you looked into any SQL parsers? Dec 5, 2014 at 0:05
  • Do you have access to your mysql server so that you can restart and change the my.cnf configuration? If so, have you considered temporarily enabling general_log and going through that instead?
    – macinnir
    Dec 5, 2014 at 1:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.