getting the list of all the databased and there table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

getting the list of all the databased and there table

Post by pelegk2 »

how can i get the list of all databases and tables on mysql server?
thanks in advance
peleg
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

install an admin tool like phpMyAdmin
http://sourceforge.net/project/showfile ... _id=220762
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Command-line wise you can login as root, then type "show databases". Then in each db, type "show tables".
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

what?
i asked hhow to do it in php!
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

mysql_list_dbs
mysql_list_tables

and humm well look for other mysql_list_"whatever"....
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

pelegk2 wrote:what?
i asked hhow to do it in php!
Both the previously mentioned ways are/can be done in PHP...heh :wink:
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Can also do it like this.

Code: Select all

<?php

$db = mysql_connect('localhost', 'root', 'password') or die(mysql_error());
$sql = 'SHOW DATABASES';
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($res)){
  echo '<b>'.$row['Database'].'</b><br />';
  mysql_select_db($row['Database']) or die(mysql_error());
  $sql = "SHOW TABLES";
  $res2 = mysql_query($sql) or die(mysql_error());
  while($row2 = mysql_fetch_assoc($res2)){
    $tblname = 'Tables_in_'.$row['Database'];
    echo '&nbsp;&nbsp;'.$row2[$tblname].'<br />';
  }
}

?>
Loads of different ways really :o
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

...and that's what I was referring too. :)
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

Post by pelegk2 »

thnaks all of u:)
Post Reply