Home > Backend Development > PHP Tutorial > Two ways to list all tables in MySQL database_PHP tutorial

Two ways to list all tables in MySQL database_PHP tutorial

WBOY
Release: 2016-07-13 17:05:32
Original
1152 people have browsed it

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;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630754.htmlTechArticlephp tutorial to list all tables in the MySQL database tutorial. The two methods PHP code are as follows: function list_tables($database) { $rs = mysql tutorial_list_tables($database); $tables = array(); while...
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template