Avinash
Avinash

Reputation: 6174

How to list all table in mysql database

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

Upvotes: 0

Views: 723

Answers (2)

Marek Karbarz
Marek Karbarz

Reputation: 29294

You want a combination of Show Columns and Show Tables

Upvotes: 2

Chris
Chris

Reputation: 101

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;
}

Upvotes: 0

Related Questions