Reputation: 13
I'm trying to list all my databases. But I only return information schema and one other table.. I checked my user settings/privileges in mysql and I have access to everything.. How can I return all databases
here is the code i used:
$set = mysql_query('SHOW DATABASES;');
$dbs = array();
while($db = mysql_fetch_row($set)) $dbs[] = $db[0]; echo implode('<br/>', $dbs);
Upvotes: 0
Views: 112
Reputation: 790
As pointed out in the comments, you really should start using mysqli instead of mysql.
This should solve your problem though:
<?php
$link = mysqli_connect("localhost", "mysql_username", "mysql_password");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$res = mysqli_query($link, "SHOW DATABASES");
while ($row = mysqli_fetch_assoc($res)) {
var_dump($row['Database']);
}
Upvotes: 1