getDatabaseName(); $columns = Db::select(" SELECT COLUMN_NAME, DATA_TYPE, COLUMN_TYPE, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_COMMENT, EXTRA FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? ORDER BY ORDINAL_POSITION ", [$database, $table]); return array_map(function ($col) { return [ 'name' => $col->COLUMN_NAME, 'type' => $col->DATA_TYPE, 'column_type' => $col->COLUMN_TYPE, 'nullable' => $col->IS_NULLABLE === 'YES', 'default' => $col->COLUMN_DEFAULT, 'comment' => $col->COLUMN_COMMENT, 'extra' => $col->EXTRA, ]; }, $columns); } /** * 获取字段名列表 */ public static function getColumnNames(string $table, ?string $database = null): array { return array_column(self::getColumns($table, $database), 'name'); } /** * 获取字段注释 map:字段名 => 注释 */ public static function getColumnComments(string $table, ?string $database = null): array { $columns = self::getColumns($table, $database); $map = []; foreach ($columns as $col) { $map[$col['name']] = $col['comment']; } return $map; } }