views:

46

answers:

2

Hi

I want to list all tables in my mysql database.

I want that each table list with column name and datatype.

So how could i do this, any query or something like that.

Running on php

Thanks

Avinash

A: 

This will return fields

//Get fields function
public function getFields($tmptable){
    $fields = array();
    $result = mysql_query("SHOW COLUMNS FROM ". $tmptable);
    if (!$result) {
        echo 'Could not run query: ' . mysql_error();
        exit;
    }
    //populate num of fields
    //$this->num_fields = mysql_num_rows($result);
    if ($this->num_fields($result) > 0) {
        while ($row = mysql_fetch_assoc($result)) {
            //polulate fields list
            foreach ($row as $field){
                $fields[] = $field;
                if($field['key'] == "PRI"){
                    //$this->primary_key_field = $field;
                }
            }

        }
    }
    return $fields;
}
Chris
+2  A: 

You want a combination of Show Columns and Show Tables

Marek Karbarz
how can we combine both of them
KoolKabin
@KoolKabin - by using 2 separate queries - can't combine them (as far as I know) into a single query
Marek Karbarz