Name
mysql_list_tables()
Synopsis
resource mysql_list_tables(database[,connection])
This function returns a results set containing a list of
tables for database. You may give an
identifier as a second argument to retrieve information for a
different connection. The mysql_tablename()
function can be used to extract the names of the tables from the
results set of this function. This function is deprecated, though. Use
the mysql_query()
function with the SHOW TABLES statement instead.
Here is an example:
...
$tables = mysql_list_tables('workrequests');
$num_tables = mysql_num_rows($tables);
for($index = 0; $index < $num_tables ; $index++) {
print mysql_tablename($tables, $index) . "\n";
}
...The first line shown here gives the database name as an argument
for the mysql_list_tables() function. The
results are stored in the $tables variable. Next,
the number of rows and the number of tables found are determined and
stored in $num_tables. Using a
for statement to loop through the list of tables in
the results set, each table name is printed out with the assistance of
mysql_tablename(). The second argument of
mysql_tablename() is adjusted incrementally
by using the $index variable, which will increase
from 0 to the value of the $num_tables
variable.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access