Posted By

neogeek on 07/01/06


Tagged

mysql database tables


Versions (?)

Who likes this?

21 people have marked this snippet as a favorite

meth
jonbaer
Fixe
n2linux
hxseven
vaaaska
blakeb
Hollow
demods
Phoenix
vali29
motoroller
digiloper
sumandahal
nb109
sarandi
umang_nine
osirisinternet
bobbym245
lfcortes
ringo380


MySQL List Database Tables


 / Published in: PHP
 

Fetch a list of tables in a specific database.

  1. if (!function_exists('mysql_list_db_tables')) {
  2.  
  3. function mysql_list_db_tables($database) {
  4.  
  5. $tables = Array();
  6.  
  7. $results = mysql_query('SHOW TABLES FROM ' . $database);
  8. while($row = @mysql_fetch_assoc($results)) { $tables[] = $row['Tables_in_' . $database]; }
  9.  
  10. return $tables;
  11.  
  12. }
  13.  
  14. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: prf_q on August 6, 2008

use http://www.php.net/manual/en/function.mysql-list-tables.php instead... or

function get_tables() {
    global $mysql;
    $tables = mysql_query("show tables", $mysql) or die(mysql_error());

    if (mysql_num_rows($tables)){
        $table_list=Array();

        while ($table_data = mysql_fetch_row($tables)){
            $table_list[] = $table_data[0];
        }
    }
    mysql_free_result($tables);

return $table_list;
}
Posted By: sarandi on July 22, 2009

mysql-list-tables is deprecated...

Posted By: sarandi on July 22, 2009

mysql-list-tables is deprecated...

You need to login to post a comment.