如何在mysql数据库中列出所有表

时间:2010-02-01 06:38:07

标签: php mysql

我想列出我的mysql数据库中的所有表。

我希望每个表列表都有列名和数据类型。

那么我怎么能这样做,任何查询或类似的东西。

在php上运行

由于

阿维纳什

2 个答案:

答案 0 :(得分:2)

您需要Show ColumnsShow Tables

的组合

答案 1 :(得分:0)

这将返回字段

//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;
}
相关问题