Home  >  Article  >  Backend Development  >  How can we write a PHP script to get a list of MySQL databases?

How can we write a PHP script to get a list of MySQL databases?

王林
王林forward
2023-09-02 23:37:05662browse

How can we write a PHP script to get a list of MySQL databases?

We can write the following PHP script to get the list of available MySQL databases -

Example

<?php
   $con = mysql_connect("localhost", "userid", "password");

   if (!$con) {
      die(&#39;Could not connect: &#39; . mysql_error());
   }
   $db_list = mysql_list_dbs($con);

   while ($db = mysql_fetch_object($db_list)) {
      echo $db->Database . "<br />";
   }
   mysql_close($con);
?>

The above is the detailed content of How can we write a PHP script to get a list of MySQL databases?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete