php tutorial Two methods to list all tables in MySQL database tutorial
The PHP code is as follows:
function list_tables($database)
{
$rs = mysql tutorial_list_tables($database);
$tables = array();
While ($row = mysql_fetch_row($rs)) {
$tables[] = $row[0];
}
Mysql_free_result($rs);
Return $tables;
}
However, since the mysql_list_tables method is outdated, 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
One solution is to set error_reporting in php.ini and not display the method obsolescence prompt
1 error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
Another method is to use an alternative approach 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;