PHP如何獲取MySQL數(shù)據(jù)庫中的所有表
在用PHP結合MySQL數(shù)據(jù)庫開發(fā)應用程序時,可能會用到數(shù)據(jù)庫中全部表信息。本文主要介紹了PHP獲取所有表信息的實現(xiàn)代碼,希望能對讀者有所幫助。
代碼如下:
- 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方法已經(jīng)過時,運行以上程序時會給出方法過時的提示信息,如下:
復制代碼 代碼如下:
- 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;
- }
關于PHP獲取MySQL數(shù)據(jù)庫中所有表的代碼實現(xiàn)已經(jīng)介紹完畢了,如果您想了解更多關于MySQL數(shù)據(jù)庫的知識,可以看一下這里的文章:http://database.51cto.com/mysql/,相信會對您有幫助的。
【編輯推薦】