Take the 2-minute tour ×

What query do I need to run in PHP to get the structure of a given table in the database? And what query do I need to run to get a list of all the tables?

share|improve this question

3 Answers 3

up vote 29 down vote accepted

To get a list of columns for a table, use the DESCRIBE SQL statement. The syntax is as follows:


To get a list of tables on the database, use this SQL statement:

share|improve this answer

To get the CREATE syntax use


Also take a look in the information_schema database. Lots of very useful information about your databases, tables, indexes, etc.

See: How to find all the tables in MySQL with specific column names in them?

share|improve this answer
$q = mysql_query('DESCRIBE tablename');
while($row = mysql_fetch_array($q)) {
    echo "{$row['Field']} - {$row['Type']}\n";

found it at http://www.electrictoolbox.com/mysql-table-structure-describe/

share|improve this answer

Your Answer


