ANIL KUMAR PANIGRAHI 's Blog

How to get list of table names from database in mysql?

Posted by: Anil Kumar Panigrahi in: ● March 25, 2010

Hi friends,

I got the requirement to display the list of table names from the database using php code. I got the solution for it, once check the below code.

1) Connect to database:

mysql_connect(“dbserver”,”dbuser”,”dbpassword”);

2)Get the list of tables from table

$result = mysql_list_tables(“dbname”);

3) Count the total number of tables

$num_tables = mysql_num_rows($result);

3) Display the tables names

for($i=0;$i<$num_rows;$i++)

{

echo  “Table : <b>”.mysql_tablename($result,$i).”</b>”;

}

mysql_free_result($result);

In this way we can the total table names from the database.

Share on Twitter

1 Comment to "How to get list of table names from database in mysql?"

1 | Gwapo2go

12 de July de 2010 to ● 10:02 am

mysql_list_tables is already depricated. You should use mysql_query() to issue SHOW TABLES command. Refer to the PHP Manual for additional details.

Write Comment

About Me

  Anil Kumar Panigrahi
  Software Engineer (PHP)
  Blogger & Founder of Anil Labs
  Baruva, India

You can share with me . . .

My Own Contributions

1) First contribution for codeigniter framework ( multi language support using google translate API ). we can get files from http://github.com/nyros/codeigniter_multilanguage


2) Audio and Video Streaming using FFMpeg and PHP -complete doc file : http://www.docstoc.com/docs/8300349/Audio-and-Video-Streaming

Twitter Updates

Follow me @anil2u
  • We will always be thankful to our teacher for all the hard work and efforts they have put in, for educating us.- Happy teachers Day . . . :) - posted on 05/09/2010 05:39:13
  • Working on shipping cost functionality (UPS and USPS) for oscommerce shopping cart - posted on 01/09/2010 09:40:03
  • If your freedom hurts others, you are not free. You must not hurt others. - Vivekananda - posted on 31/08/2010 06:02:49
  • Another day starts with full of energy . Good Morning - posted on 31/08/2010 02:54:12
  • Nice explanation about php oops concept : http://youropensource.com/projects/182-OOPS-Concepts-in-PHP - posted on 30/08/2010 19:56:17