Foreach Table in a Database -- Is it possible?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
the9ulaire
Forum Commoner
Posts: 74
Joined: Mon Jun 11, 2007 11:31 am

Foreach Table in a Database -- Is it possible?

Post by the9ulaire »

Is it possible to do some sort of query of a foreach on a database? Selecting every table name in the database?
m4rv5
Forum Newbie
Posts: 13
Joined: Fri Apr 11, 2008 12:49 am

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

Post 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;
      }
}
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

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

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply