Home  >  Article  >  Backend Development  >  PHP obtains the implementation code of all tables in the MySQL database

PHP obtains the implementation code of all tables in the MySQL database

PHP中文网
PHP中文网Original
2017-03-23 10:22:421411browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn