In usePHPIntegrationMySQL databaseDuring application development, all table information in the database may be used. This article mainly introduces PHP implementation code for getting all table information, hoping to help readers.
The Code is as follows:
- 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;
-
- }
However, because the mysql_list_tables method is out of date, a prompt message indicating that the method is out of date is displayed when you run the above program, as shown below:
Copy the Code as follows:
- Deprecated: Function mysql_list_tables) is deprecated in … on line xxx
One solution is to set error_reporting in php. ini without displaying the method outdated prompt.
Copy the Code as follows:
- error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
Another method is to use the alternative method officially recommended by PHP:
Copy the Code as follows:
- 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;
-
- }
The code implementation for PHP to obtain all tables in the MySQL database has been introduced. If you want to know