我有这个类“数据库”,它扩展了 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;
}
如有任何建议,我们将不胜感激!
最佳答案
好吧,我找到了我的解决方案,它根本不使用 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] =>
)
)
关于php - PDO 和数据库类 - 获取表模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16971866/