Name
mysql_list_tables( )
Synopsis
mysql_list_tables(database
[,connection
])
This returns a results set containing a list of tables for
database
. An identifier may be given as a
second argument to the function 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.
... $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
$num_tables
variable.
Get MySQL in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.