可能的重复:
Mysql 选择枚举值 https://stackoverflow.com/questions/4644220/mysql-select-enum-values
我已经设立了一个专栏Mysql
:
type: ENUM
Length/Values: '01','02','03','04','05','06','07','08','09','10','11','12'
我正在尝试从数据库中检索这些值:
我发现另一篇文章有同样的问题,但我的代码不起作用
$type = $mysqli->query( "SHOW COLUMNS FROM {$tableName} WHERE Field = 'type'" )->fetch_object()->Type;
preg_match('/^enum\((.*)\)$/', $type, $matches);
foreach( explode(',', $matches[1]) as $value )
{
$enum[] = trim( $value, "'" );
}
return $enum;
我得到类型Text
代替ENUM
您应该解析来自information_schema
.columns
table -
SELECT
column_type
FROM
information_schema.columns
WHERE
table_schema = 'your_schema' AND table_name = 'your_table' AND column_name = 'your_column'
...另一个查询 -
SELECT
TRIM(TRAILING ')' FROM TRIM(LEADING '(' FROM TRIM(LEADING 'enum' FROM column_type))) column_type
FROM
information_schema.columns
WHERE
table_schema = 'your_schema' AND table_name = 'your_table' AND column_name = 'your_column';
会有这样的事情——enum('01','02','03')
。在 php 应用程序中解析此字符串。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)