Home > Backend Development > PHP Tutorial > 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中文网
Release: 2023-02-28 19:34:01
Original
1466 people have browsed it

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;
}
Copy after login

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
Copy after login

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
Copy after login

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;
}
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template