Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Get a List of Databases from MySQL Servers
How To Get a List of Databases from MySQL Servers? - MySQL FAQs - PHP Connections and Query Execution
✍: FYIcenter.com

Once you got a MySQL server connection object successfully, you need to know what databases are available on the server and which database you should use to manage your tables and data. To get a list of all available databases on your MySQL server, you can use the mysql_list_dbs() function. Note mysql_list_dbs() will not return an array of database names. It returns a result object, which requires mysql_fetch_object() call to loop through each database object.
The tutorial exercise below shows you a good example of how to get a list of databases as a result object. Then "while" loop is used to fetch each database object from the result object. Finally, an object property "$obj->Database" is used to get the database name:
<?php
  $con = mysql_connect('localhost:8888', 'dev', 'iyf');
  print("List of databases:\n");
  $res = mysql_list_dbs($con);
  while ($obj = mysql_fetch_object($res)) {
     print($obj->Database . "\n");
  }
  mysql_close($con); 
?>
If you run this script, you will get something like this:
List of databases: information_schema mysql test
2007-05-10, 5702👍, 0💬
Popular Posts:
WHat will be the result of the following code? #define TRUE 0 // some code while (TRUE) { // some co...
How To Compare Two Strings with strcmp()? - PHP Script Tips - PHP Built-in Functions for Strings PHP...
How To Blend a Color Layer to a Image? - PSP Tutorials - Fading Images to Background Colors with PSP...
interview.FYIcenter.com offers a collections of interview questions and answers for software and Web...
Jack developed a program by using a Map container to hold key/value pairs. He wanted to make a chang...