The code is as follows:
function list_tables($database) { $rs = mysql_list_tables($database); $tables = array(); while ($row = mysql_fetch_row($rs)) { $tables[] = $row[0]; } mysql_free_result($rs); return $tables; }
But because the mysql_list_tables method is obsolete, when running the above program, a prompt message indicating that the method is outdated will be given, as follows:
Deprecated: Function mysql_list_tables() is deprecated in … on line xxx
A solution is Set error_reporting in php.ini and do not display the method obsolescence prompt message
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
Another method is to use the alternative method officially recommended by PHP:
function list_tables($database) { $rs = mysql_query("SHOW TABLES FROM $database"); $tables = array(); while ($row = mysql_fetch_row($rs)) { $tables[] = $row[0]; } mysql_free_result($rs); return $tables; }
Related articles:
php code to get all table names in mysql database
PHP method to get mysql database table fields
php Get the mysql database version number mysql_get_server_info