List Tables of MySql Database

by MD on 2009/03/06

Using code below, all the tables in MySql database can be listed

<?php
# ======= Put Appropriate value in below lines =======
define('DB_HOST', 'localhost');
define('DB_USER', 'user name');
define('DB_PASSWORD', 'password');
define('DB_NAME', 'database name');

# ======= Do not change code below this line =======

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die ('I cannot connect to the database because: ' . mysql_error());

$db = mysql_select_db(DB_NAME, $link);

$table_list = mysql_query("SHOW TABLES FROM ".DB_NAME."") or die("DB Error, could not list tables\n ".mysql_error());

while ($row = mysql_fetch_row($table_list))
{
	echo $row[0];
	echo "<br />";
}

mysql_free_result($table_list);
mysql_close();
?>

You may also like:

Leave a Comment

Previous post:

Next post: