PDO和数据库类 - 获取表模式

Tob*_*eek 1 php mysql pdo

我有这个类"数据库",它扩展了PDO,我可以做搜索,找到所有这样的完美:

public function select($sql, $array = array(), $fetchMode = PDO::FETCH_ASSOC){
    $sth = $this->prepare($sql);
    foreach ($array as $key => $value) {
        $sth->bindValue("$key", $value);
    }

    $sth->execute();
    return $sth->fetchAll($fetchMode);
}
Run Code Online (Sandbox Code Playgroud)

但现在我想要一个允许我检索表模式的函数...

我尝试使用PDO:cubic_schema,但无法使其工作.我不断发现要么无法找到常量,要么无法找到方法,这是一个尝试......

    public function schema($table) {
    $table_information = $this->cubrid_schema(PDO::CUBRID_SCH_CLASS, $table);
    return $table_information;
}
Run Code Online (Sandbox Code Playgroud)

任何意见,将不胜感激!

Tob*_*eek 6

好的,我找到了我的解决方案,根本就不使用Cubric ....

public function schema($table) {

    $q = $this->prepare("SHOW COLUMNS FROM `$table`");
    $q->execute();
    $table_fields = $q->fetchAll();
}
Run Code Online (Sandbox Code Playgroud)

这会返回:

Array
(
    [0] => Array
        (
            [Field] => dataid
            [0] => dataid
            [Type] => int(11)
            [1] => int(11)
            [Null] => NO
            [2] => NO
            [Key] => PRI
            [3] => PRI
            [Default] => 
            [4] => 
            [Extra] => auto_increment
            [5] => auto_increment
        )

    [1] => Array
        (
            [Field] => text
            [0] => text
            [Type] => varchar(255)
            [1] => varchar(255)
            [Null] => NO
            [2] => NO
            [Key] => 
            [3] => 
            [Default] => 
            [4] => 
            [Extra] => 
            [5] => 
        )

)
Run Code Online (Sandbox Code Playgroud)