Cml\Db\MySql\Pdo::getDbFields PHP Method

getDbFields() public method

获取表字段
public getDbFields ( string $table, mixed $tablePrefix = null, integer $filter ) : mixed
$table string 表名
$tablePrefix mixed 表前缀 为null时代表table已经带了前缀
$filter integer 0 获取表字段详细信息数组 1获取字段以,号相隔组成的字符串
return mixed
    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;
    }