Programming, website development forum Get latest updates by RSS Follow TechnicalTalk on Twitter Follow TechnicalTalk on Facebook 
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password    
  Forgot your password?  

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

Listing tables in Mysql database

 
webmaster forum
hardy  Offline
Activity
0%
 
New Coder
Posts: 25
Topics: 16
December 18, 2008, 11:59:17 PM

Hello

I want to list all the tables in the mysql database using php? How can I do that? i know how to fetch the records but I want to fetch the table names from database.

Any help regarding this is appreciated.

Thanks
 
webmaster forum
polas  Offline
Activity
33.33%
 
Code Guru
Gender: Male
Posts: 1399
Topics: 85
WWW
December 19, 2008, 03:03:42 AM

Well, I would guess there are quite a few ways to do this - personally, the way I have always done it is by using SQL.

From looking on the internet, an SQL statement like :

SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'db_name' (where db_name is changed to become your database name)

should give a result.

In PHP (after opening the DB etc.) I would have something like:

$c_result = mysql_connect("localhost", "user", "pass");
$s_result = mysql_select_db("database", $c_result);
$SQLQuery ="SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'db_name'";
$q_result = mysql_query($SQLQuery, $c_result);
$numrows = mysql_num_rows($q_result);
for ($rownum=0; $rownum < $numrows; $rownum++)
{
   $myname= mysql_result($q_result, $rownum,"table_name");   
        print $myname;
}

Something like that - its just a guestimate, so you will have to play around with it to get it working properly

Mesham Type Oriented Parallel Programming Language, Free online technical support
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.15 | SMF © 2011, Simple Machines


Google visited last this page January 27, 2012, 04:52:42 AM