Collections:
List All Existing Databases in MySQL
How To Get a List of Databases from MySQL Servers in MySQL?
✍: 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
⇒ Creating a New Database in MySQL
⇐ Close MySQL Connection Objects in MySQL
2017-11-11, 2812🔥, 0💬
Popular Posts:
Can Binary Strings Be Converted into NUMERIC or FLOAT Data Types in SQL Server Transact-SQL? Can bin...
Where Is the Export Dump File Located in Oracle? If you are not specifying the dump directory and fi...
What Privilege Is Needed for a User to Delete Rows from Tables in Another Schema in Oracle? For a us...
Why I Can Not Enter 0.001 Second in DATETIME values in SQL Server Transact-SQL? If you enter millise...
How To Connect the Oracle Server as SYSDBA in Oracle? This is Step 4. The best way to connect to the...