I am trying to find a way to get a list of all of the tables referenced by the fields that are returned in a MySQL query using PHP. I know that EXPLAIN gives table information, but it returns the table alias if one is used.
i.e. EXPLAIN will return "tablea", "tableb" and "test" from:
SELECT test.* FROM t1
JOIN t2 ON t2.id = t1.id
JOIN alias AS test ON test.eid = t2.eid
However, in the example above, I would only like to get "alias".
With simple queries, I can interrogate the string and pull out the information, but this gets quite complicated when taking into account subqueries, field aliases and the various joins that could be included.
Is there an easy way to do this? If not, I would appreciate any pointers on how this can be done!