public function getDbFields($table, $tablePrefix = null, $filter = 0)
{
static $dbFieldCache = [];
if ($filter == 1 && Cml::$debug) {
return '*';
}
//debug模式时直接返回*
$table = is_null($tablePrefix) ? strtolower($table) : strtolower($tablePrefix . $table);
$info = false;
if (isset($dbFieldCache[$table])) {
$info = $dbFieldCache[$table];
} else {
Config::get('db_fields_cache') && ($info = \Cml\simpleFileCache($this->conf['master']['dbname'] . '.' . $table));
if (!$info || Cml::$debug) {
$stmt = $this->prepare("SHOW COLUMNS FROM {$table}", $this->rlink, false);
$this->execute($stmt, false);
$info = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$info[$row['Field']] = ['name' => $row['Field'], 'type' => $row['Type'], 'notnull' => (bool) ($row['Null'] === ''), 'default' => $row['Default'], 'primary' => strtolower($row['Key']) == 'pri', 'autoinc' => strtolower($row['Extra']) == 'auto_increment'];
}
count($info) > 0 && \Cml\simpleFileCache($this->conf['master']['dbname'] . '.' . $table, $info);
}
$dbFieldCache[$table] = $info;
}
if ($filter) {
if (count($info) > 0) {
$info = implode('`,`', array_keys($info));
$info = '`' . $info . '`';
} else {
return '*';
}
}
return $info;
}