src/Leevel/Database/Mysql.php
public function tableColumns(string $tableName, $master = false): array
    {
        $sql = 'SHOW FULL COLUMNS FROM '.
            $this->normalizeTableOrColumn($tableName);

        $result = [
            'list'           => [],
            'primary_key'    => null,
            'auto_increment' => null,
        ];

        if (($columns = $this->query($sql, [], $master, PDO::FETCH_ASSOC))) {
            foreach ($columns as $column) {
                $tmp = [];
                $tmp['name'] = $column['Field'];

                if (preg_match('/(.+)\((.+)\)/', $column['Type'], $matche)) {
                    $tmp['type'] = $matche[1];
                    $tmp['length'] = $matche[1];
                } else {
                    $tmp['type'] = $column['Type'];
                    $tmp['length'] = null;
                }

                $tmp['primary_key'] = 'pri' === strtolower($column['Key']);
                $tmp['auto_increment'] = false !== strpos($column['Extra'], 'auto_increment');

                if (null !== $column['Default'] &&
                    'null' !== strtolower($column['Default'])) {
                    $tmp['default'] = $column['Default'];
                } else {
                    $tmp['default'] = null;
                }

                $tmp['comment'] = $column['Comment'];

                $result['list'][$tmp['name']] = $tmp;

                if ($tmp['auto_increment']) {
                    $result['auto_increment'] = $tmp['name'];
                }

                if ($tmp['primary_key']) {
                    if (!is_array($result['primary_key'])) {
                        $result['primary_key'] = [];
                    }

                    $result['primary_key'][] = $tmp['name'];
                }
            }
        }

        unset($columns, $sql);

        return $result;
    }
public function tableColumns(string $tableName, $master = false): array
    {
        $sql = 'SHOW FULL COLUMNS FROM '.
            $this->normalizeTableOrColumn($tableName);

        $result = [
            'list'           => [],
            'primary_key'    => null,
            'auto_increment' => null,
        ];

        if (($columns = $this->query($sql, [], $master, PDO::FETCH_ASSOC))) {
            foreach ($columns as $column) {
                $tmp = [];
                $tmp['name'] = $column['Field'];

                if (preg_match('/(.+)\((.+)\)/', $column['Type'], $matche)) {
                    $tmp['type'] = $matche[1];
                    $tmp['length'] = $matche[1];
                } else {
                    $tmp['type'] = $column['Type'];
                    $tmp['length'] = null;
                }

                $tmp['primary_key'] = 'pri' === strtolower($column['Key']);
                $tmp['auto_increment'] = false !== strpos($column['Extra'], 'auto_increment');

                if (null !== $column['Default'] &&
                    'null' !== strtolower($column['Default'])) {
                    $tmp['default'] = $column['Default'];
                } else {
                    $tmp['default'] = null;
                }

                $tmp['comment'] = $column['Comment'];

                $result['list'][$tmp['name']] = $tmp;

                if ($tmp['auto_increment']) {
                    $result['auto_increment'] = $tmp['name'];
                }

                if ($tmp['primary_key']) {
                    if (!is_array($result['primary_key'])) {
                        $result['primary_key'] = [];
                    }

                    $result['primary_key'][] = $tmp['name'];
                }
            }
        }

        unset($columns, $sql);

        return $result;
    }
取得数据库表字段信息.

@param string   $tableName
@param bool|int $master

@return array