Mysqli php databases

Good morning.

I was wondering if there is a PHP way to specify all available databases using mysqli . The following works smoothly in mysql (see php docs ):

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); $db_list = mysql_list_dbs($link); while ($row = mysql_fetch_object($db_list)) { echo $row->Database . "\n"; } 

Is it possible to change:

 $db_list = mysql_list_dbs($link); // mysql 

into something like:

 $db_list = mysqli_list_dbs($link); // mysqli 

If this does not work, would it be possible to convert the created mysqli connection to regular mysql and continue fetching / querying on the new converted connection?

+6
php mysqli
source share
2 answers

It doesn't seem like there is a function available for this, but you can execute the show databases; query show databases; , and the returned rows will be available in the database.

+8
source share

I understand this is an old thread, but searching the web still does not help. Here is my solution;

 $sql="SHOW DATABASES"; $link = mysqli_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql: ' . mysqli_error($link).'\r\n'); if (!($result=mysqli_query($link,$sql))) { printf("Error: %s\n", mysqli_error($link)); } while( $row = mysqli_fetch_row( $result ) ){ if (($row[0]!="information_schema") && ($row[0]!="mysql")) { echo $row[0]."\r\n"; } } 
+6
source share

All Articles