1

我有这个类“数据库”,它扩展了 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);
}

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

我尝试使用 PDO:cubic_schema,但无法使其工作。我一直在找不到常量或找不到方法,这是一个尝试...

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

任何意见,将不胜感激!

4

1 回答 1

6

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

public function schema($table) {

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

这返回:

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] => 
        )

)
于 2013-06-07T15:36:20.713 回答