当前位置:首页 > PHP教程 > PHP高级教程

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

复制代码 代码如下:

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;
}


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!