think\db\connector\Mysql::getFields PHP Метод

getFields() публичный Метод

取得数据表的字段信息
public getFields ( string $tableName ) : array
$tableName string
Результат array
    public function getFields($tableName)
    {
        $this->initConnect(true);
        list($tableName) = explode(' ', $tableName);
        if (strpos($tableName, '.')) {
            $tableName = str_replace('.', '`.`', $tableName);
        }
        $sql = 'SHOW COLUMNS FROM `' . $tableName . '`';
        // 调试开始
        $this->debug(true);
        $pdo = $this->linkID->query($sql);
        // 调试结束
        $this->debug(false, $sql);
        $result = $pdo->fetchAll(PDO::FETCH_ASSOC);
        $info = [];
        if ($result) {
            foreach ($result as $key => $val) {
                $val = array_change_key_case($val);
                $info[$val['field']] = ['name' => $val['field'], 'type' => $val['type'], 'notnull' => (bool) ('' === $val['null']), 'default' => $val['default'], 'primary' => strtolower($val['key']) == 'pri', 'autoinc' => strtolower($val['extra']) == 'auto_increment'];
            }
        }
        return $this->fieldCase($info);
    }