Saturday, December 13, 2008

How to list all tables in a mysql database using php

Following code will show you how to get all the table names inside a given mysql database. to do this you only need know about the mysql query "SHOW TABLES".
following example show you how to retrieve query the result using php.


<?php

//set your DB connection
mysql_connect('localhost', 'root', '');
//select your DB
mysql_select_db('test');

$query = "SHOW TABLES";
$result = mysql_query($query);

while($data = mysql_fetch_array($result))
{
echo $data[0];
echo '<br />';
}

?>


Get custom programming done at GetAFreelancer.com!

No comments:

Post a Comment