Log in

View Full Version : Resolved Retrieve mysql table names?



liamallan
07-27-2010, 01:26 PM
hey guys!

is it possible to retrieve the names of all tables on a mysql database with some php?

i recently ran into a problem where i cant access my hosts control panel, therefor i cant access my mysql database as u need to access it from the control panel!

i have been working hard on a mysql management system which is coming along very well, and pretty proud of it too!

but.... i cant remember all of my table names, only a few.

i would be extremely grateful if someone could help me achieve this!

thanx
:D

liamallan
07-27-2010, 01:59 PM
no worries guys, i finally worked it out!

here is how i done it incase anyone else has the same question:

<?php
mysql_connect("localhost", "username", "password");
$result = mysql_list_tables("database");
$num_rows = mysql_num_rows($result);
for ($i = 0; $i < $num_rows; $i++) {
echo "Table: ", mysql_tablename($result, $i), "\n";
}

mysql_free_result($result);
?>

fastsol1
07-27-2010, 02:14 PM
Try this function - mysql_list_tables() - how to use is at http://php.net/manual/en/function.mysql-list-tables.php