[thelist] Remedial PHP - MySQL

Jay Blanchard jay.blanchard at niicommunications.com
Wed Feb 16 09:49:14 CST 2005

I have several mysql databases. I'm trying, without a lot of success 
this morning (must be tired), to use PHP to get a list of the tables 
in one of those databases:

     if (!($listOfTables = mysql_list_tables($link, 1))) {
     	echo("Dang! No Tables Found!");

I think my syntax is off. I'm not sure how to point this command at 
one database ... or does it return all of the tables from all of the 
databases and I have to segregate them out of the results set?


$dbname = 'mysql_dbname';

if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
   echo 'Could not connect to mysql';

$result = mysql_list_tables($dbname);

if (!$result) {
   echo mysql_error() . "\n";

while ($row = mysql_fetch_row($result)) {
   echo "Table: $row[0]\n";

More information about the thelist mailing list