This example describes how PHP lists all the databases in MySQL. Share to everyone for your reference. Specifically as follows:
The PHP code is as follows:
<?php define (' NL ', ' \ n ');
Define (' TB ', ');
Connecting to MySQL.
$conn = @mysql_connect (' localhost ', ' username ', ' password ') or Die (Mysql_errno (). ": Mysql_error (). NL); Attempt to get a list of the MySQL databases//already set up in I account.
This is done//using the PHP Function:mysql_list_dbs () $result = Mysql_list_dbs ($conn);
Output the list echo ' <ul class= ' projects ' > '. NL; * Using:mysql_fetch_object ()//---------------------------while ($row = Mysql_fetch_object ($result)): Echo TB .' <li> '. $row->database. '
</li> '. NL;
Endwhile; *///* Using:mysql_fetch_row ()//------------------------while ($row = Mysql_fetch_row ($result)): Echo TB. ' <li> '. $row [0]. '
</li> '. NL;
Endwhile; *///* USING:MYSQL_FETCH_ASSOC ()//--------------------------while ($row = Mysql_fetch_assoc ($result)): Echo T B. ' <li> ' $row [' Database ']. '
</li> '. NL;
Endwhile;
* * echo ' </ul> '. NL; Free resources /close MySQL Connection mysql_free_result ($result);
Mysql_close ($conn); ?>
I hope this article will help you with your PHP programming.