Get mysql tables in a query
There is any way to get the tables I'm using in a query?

The first method I was using was with regular expressions:

    // result[1] = "SELECT"
    // result[3] = "All between FROM and WHERE, ex: `users`, ex: `users`, `test`
    
    if($result[1] == "SELECT" && !preg_match('/FROM\s*(.*?,.*?)\s*WHERE/i', $query, $res))
    {
        $tables = preg_replace('/`|\'|\s/i', '', $result[3]); // strip ` or ' or spaces
        $tables = explode(",", $tables);
        sort($tables);
    }

But there are complex mysql queries, so the next method I used is:

    EXPLAIN SELECT...

and get the tables from the result array.

The problem comes with counts, I know that in MyISAM db's **the number of rows is stored**, so if you do the next query:

    SELECT COUNT(*) FROM users

You don't get the table that is used in the query, you get "Select tables optimized away" because any table is used.

So, **there is another method to get tables used in a query**? Thanks
Get mysql tables in a query
===

There is any way to get the tables I'm using in a query?

The first method I was using was with regular expressions:

    // result[1] = "SELECT"
    // result[3] = "All between FROM and WHERE, ex: `users`, ex: `users`, `test`
    
    if($result[1] == "SELECT" && !preg_match('/FROM\s*(.*?,.*?)\s*WHERE/i', $query, $res))
    {
        $tables = preg_replace('/`|\'|\s/i', '', $result[3]); // strip ` or ' or spaces
        $tables = explode(",", $tables);
        sort($tables);
    }

But there are complex mysql queries, so the next method I used is:

    EXPLAIN SELECT...

and get the tables from the result array.

The problem comes with counts, I know that in MyISAM db's **the number of rows is stored**, so if you do the next query:

    SELECT COUNT(*) FROM users

You don't get the table that is used in the query, you get "Select tables optimized away" because any table is used.

So, **there is another method to get tables used in a query**? Thanks