如何使用php在MySQL在数据库中获得枚举的可能值?
技术问答
339 人阅读
|
0 人回复
|
2023-09-13
|
我正在设立专栏Mysql:
+ t3 w( b3 B; f) |: f类型: ENUM. S3 B, p5 J! R3 ~: a8 N
Length/Values:01,02,03,04,05,06,07,08,09' T' B$ e. W& a
我试图从数据库中检索这些值:5 r% Z1 a9 s) {" a: C5 W
我发现了另一个帖子,但也有同样的问题,但我的代码不能正常工作
4 D. u$ _+ [. ]" x/ U$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
; O5 @' b) K4 p0 q( o9 Y# S / a8 |' [0 b( G _/ U/ P+ c5 D
解决方案: 2 A8 o) w1 T' X+ `
您应该从中分析信息information_schema。columns桌子 -6 ?1 F! O" }3 G9 w& Z
SELECT column_typeFROM information_schema.columnsWHERE table_schema = 'your_schema' AND table_name = 'your_table' AND column_name = 'your_column'…另一个查询-4 A3 T$ C) Y' q O7 p1 J2 ?( s0 V- v$ y
SELECT TRIM(TRAILING ')' FROM TRIM(LEADING '(' FROM TRIM(LEADING 'enum' FROM column_type))) column_typeFROM information_schema.columnsWHERE table_schema = 'your_schema' AND table_name = 'your_table' AND column_name = 'your_column';会有这样的事- enum01,02,03。php分析应用程序中的字符串。 |
|
|
|
|
|