In
You can use the mysql_list_dbs () function to query the databases that exist in the system. The syntax format is as follows:
Resource mysql_list_dbs ([resource $ link_identifier])
The results returned by the mysql_list_dbs () function include all databases on the MySQL server. The following is an example of how PHP obtains all databases:
- <? Php
- $ Connection = mysql_connect ("localhost", "root"
, "Root") or die ("failed to connect to the server ");
- $ Db_list = mysql_list_dbs ($ connection );
- While ($ row = mysql_fetch_object
($ Db_list )){
- Echo $ row->Database ."< Br>";
- Echo"< Hr>";
- }
- Mysql_close ($ connection );
- ?>
In the above PHP code, the mysql_fetch_object () function is used in the loop output result set. The usage of the mysql_fetch_object () function is similar to that of the mysql_fetch_array () function. The difference is mysql_fetch_array () the function returns an array, while the mysql_fetch_object () function returns an object. The syntax format of the mysql_fetch_object () function is as follows:
Object mysql_fetch_object (resource $ result)