mysql_list_tables() function in PHP
What is mysql_list_tables() function in PHP?
How does mysql_list_tables() works?
Explanation
This
mysql_list_tables function list all the tables in a MySQL database.
Syntaxresource mysql_list_tables ( string database [, resource link_identifier])
Returns result pointer resource on success, or FALSE on failure.
mysql_list_tables() function returns a result pointer containing all the table names for given database. The
mysql_tablename() is used to extract the actual table names from the returned result pointer.
This function is deprecated. It is preferable to use
mysql_query() to issue a SQL SHOW TABLES [FROM db_name] [LIKE 'pattern'] to list table names of given database.
Example
<?php //Attempt to connect to the default database server $link = mysql_connect("mysql_host", "mysql_user", "mysql_password") or die ("Could not connect"); //return result pointer containing list of table names $list = mysql_list_tables ("database"); $i = 0; //extract table names form the result pointer while ($i < mysql_num_rows ($list)) { $tb_names[$i] = mysql_tablename ($list, $i); echo $tb_names[$i] . "<BR>"; $i++; } ?> |
Above code returns a result pointer to retrieve list of table names for given database using mysql_list_tables function.
mysql_tablename or
mysql_fetch_row is used to fetch list of table name returned by result pointer.
RESULT:
table1
table2
table3...
See also: mysql_list_dbs() and
mysql_tablename().