如何在MySQL数据库中获取枚举可能的值? [英] How can I get enum possible values in a MySQL database?

查看:455
本文介绍了如何在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;
}

这篇关于如何在MySQL数据库中获取枚举可能的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆