Get List of MySQL Databases Using PHP Script



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('Could not connect: ' . mysql_error());
   }
   $db_list = mysql_list_dbs($con);

   while ($db = mysql_fetch_object($db_list)) {
      echo $db->Database . "<br />";
   }
   mysql_close($con);
?>
Updated on: 2020-06-22T14:31:14+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements