如何在MySQL数据库中获取枚举可能的值?

问题描述:

我想用数据库中的枚举可能的值自动填充我的下拉菜单.在MySQL中有可能吗?

I want to populate my dropdowns with enum possible values from a DB automatically. Is this possible in MySQL?

我为您提供了一个codeigniter版本.它还会从值中去除引号.

I have a codeigniter version for you. It also strips the quotes from the values.

function get_enum_values( $table, $field )
{
    $type = $this->db->query( "SHOW COLUMNS FROM {$table} WHERE Field = '{$field}'" )->row( 0 )->Type;
    preg_match("/^enum\(\'(.*)\'\)$/", $type, $matches);
    $enum = explode("','", $matches[1]);
    return $enum;
}