Mysql选择枚举值 [英] Mysql Select Enum Values
问题描述
我需要选择列的枚举值。从搜索中我发现两种方式:
I need to select the enum values of a column. From searching I've found two ways:
SELECT column_type FROM information_schema.columns
WHERE table_name = 'MyTable' AND column_name = 'MyColumn';
另一个:
SHOW COLUMNS FROM `mytable` WHERE field = 'type'
虽然第一个查询会给我这个信息:
Although the first query will give me this info:
enum('value1','value2','value3')
第二个查询给出了相同的附加列。我宁愿只是得到这些值没有枚举()和逗号,是可能的,还是需要解析出来的值?不,这很难只是检查是否有一个更简单的方法。
The 2nd query gives me the same and with additional columns as well. I would prefer to just get those values without the "enum()" and commas, is it possible, or do I need to parse the values out? Not that it's hard just checking if there is an easier way.
假设没有更简单的方法,以上两个查询中哪一个更好地使用?我注意到第二个查询没有显示我运行它的查询时间,我几乎以为它根本不需要任何时间。但是,如果我打开分析器,我可以看到它需要时间,但它看起来有点快。那么第二个查询是否更有效?
Assuming there is no easier way, which of the two queries above is better to use? I noticed that the 2nd query doesn't show the query time when I ran it, I almost thought it didn't require any time at all. But if I turn on the profiler I can see that it does take time, but it seem a bit faster. So would the 2nd query be more efficient?
推荐答案
我想你不能选择这些值,我最终解析值得注意的是:
I guess you can't select those values out, I ended up parsing the values out with this:
$result = str_replace(array("enum('", "')", "''"), array('', '', "'"), $result);
$arr = explode("','", $result);
return $arr;
这篇关于Mysql选择枚举值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!