Page 1 of 1

Foreach Table in a Database -- Is it possible?

Posted: Fri Apr 11, 2008 8:54 pm
by the9ulaire
Is it possible to do some sort of query of a foreach on a database? Selecting every table name in the database?

Re: Foreach Table in a Database -- Is it possible?

Posted: Fri Apr 11, 2008 9:40 pm
by m4rv5
try this:

http://snipplr.com/view/177/mysql-list-database-tables/

Code: Select all

 
if (!function_exists('mysql_list_db_tables')) {
      function mysql_list_db_tables($database) {
           $tables = Array();
           $results = mysql_query('SHOW TABLES FROM ' . $database);
           while($row = @mysql_fetch_assoc($results)) { 
                $tables[] = $row['Tables_in_' . $database]; 
           }
           return $tables;
      }
}

Re: Foreach Table in a Database -- Is it possible?

Posted: Fri Apr 11, 2008 11:00 pm
by s.dot
It is preferred to use the query as shown above .. 'SHOW TABLES FROM `database`' instead of the listing tables functions.

I recently wrote a query manager. Was kinda cool.. like a very very lightweight phpmyadmin.