源代码如下:

<?php

   mysql_connect(\"127.0.0.1\",\"root\",\"password\");

   $tables = mysql_list_tables(\"information_schema\");

   while (list($table) = mysql_fetch_row($tables)) {
      echo \"$table <br />\";
   }

?>

但由于mysql_fetch_row函数已经过时,因此运行上面代码会出现以下错误:

Deprecated: Function mysql_list_tables() is deprecated 

 

我们可以使用mysql_query("SHOW TABLES FROM $data "); 代替mysql_fetch_row函数,因此正确是源代码如下:

<?php

   mysql_connect(\"127.0.0.1\",\"root\",\"password\");

   $tables = mysql_query(\"SHOW TABLES FROM information_schema\"); 

   while (list($table) = mysql_fetch_row($tables)) {
      echo \"$table <br />\";
   }

?>

本示例获取本地数据库服务器上information_schema数据库的所有表名称,

收藏 打印