Jump to content


Photo

PHP SHOW DATABASES


  • Please log in to reply
3 replies to this topic

#1 schutzy

schutzy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 May 2006 - 01:12 AM

Hello All,

I am (attempting to write) writing an admin web interface for a CMS and as usual my first hurdle that I have to jump appears on the first line of real code...:(

The admin's function is to allow simple database management for multiple mysql databases via a browser. The issue that I am having right now is that I am trying to retrieve the names of all of the mysql databases that have been created. Using the command line this is a simple SHOW DATABASE; However, the mysql_query doesn't return any values.

Here's the code:

$dbquery = mysql_query("SHOW DATABASES;");
$i = 0;
while ($row = mysql_fetch_assoc($dbquery)) {
$arr[$i] = $row['post_title'];
echo "<br> $i=$arr[$i]";
$i++ ;
}

This is probably a stupid post but what the heck

Schutzy




#2 Crimpage

Crimpage
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts
  • LocationBrisbane, Australia

Posted 25 May 2006 - 06:35 AM

Change

$arr[$i] = $row['post_title'];

to

$arr[$i] = $row['Database'];

Otherwise, I just copied and pasted your code and all worked fine.

#3 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 25 May 2006 - 08:17 AM

This works for me, returns all the databases on the server...

$dbquery = mysql_query("SHOW DATABASES");

$i = 0;
while ($row = mysql_fetch_assoc($dbquery)) {
    $arr[$i] = $row['Database'];
    echo "<br> ". $i ." = " .$arr[$i];
    $i++;
}


#4 schutzy

schutzy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 May 2006 - 05:19 PM

Thanks All!

I'm testing it right now...


Schutzy




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users