1

I want to use PHP to return a list of my tables containing a specific word.

I found mysql_tablename but apparently this function has been deprecated. How would I go about doing this?

2
  • I remember it's doable from a query to the MySQL server, something with schema in it, can't remember exactly... Commented Jan 7, 2012 at 20:07
  • Sorry, I should have been clearer, the word I'm looking for (a username) is in one of the fields within one of the tables, not within one of the table names. But I think I'll be able to work it out, thanks for the help! Commented Jan 7, 2012 at 20:15

3 Answers 3

2
$q = mysql_query("SHOW TABLES LIKE 'pattern'");

while ($row = @mysql_fetch_row($q))
{
    echo $row[0]."<br>";
}
Sign up to request clarification or add additional context in comments.

3 Comments

I think your answer it's not ok because a database needs to be selected in order to work.
so you can use SHOW TABLES IN database LIKE 'pattern'
The docs here php.net/manual/en/function.mysql-tablename.php state its optional (in [])
1

You can Issue a query against information_schema.tables, should be something like

select * from information_schema.tables where table_name like '%keyword%';

1 Comment

'information_schema.tables' seems to always return the same result? 'Resource id #6'
1

Query the MySQL server for it:

SELECT table_name FROM INFORMATION_SCHEMA.TABLES
  WHERE table_schema = 'db_name'
  [AND table_name LIKE 'wild']

Source


For tables containing a specific word, use the LIKE keyword to match it in the WHERE clause.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.