Home > Backend Development > PHP Tutorial > PHP 获取MySQL数据库里所有表的实现代码_PHP

PHP 获取MySQL数据库里所有表的实现代码_PHP

WBOY
Release: 2016-06-01 12:14:48
Original
927 people have browsed it
复制代码 代码如下:
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;
}

但由于mysql_list_tables方法已经过时,运行以上程序时会给出方法过时的提示信息,如下:
复制代码 代码如下:
Deprecated: Function mysql_list_tables() is deprecated in … on line xxx

一个处理办法是在php.ini中设置error_reporting,不显示方法过时提示信息
复制代码 代码如下:
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED

另一个方法是使用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 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template