在model中建立这样的模型,在其中写入获取枚举类的方法 请勿盗版,转载请加上出处http://blog.csdn.net/yanlintao1 class Student extends Zend_Db_Table{ protected $_name ='student'; protected $_primary ='id'; function getPartyEnum($enumname){ //适
在model中建立这样的模型,在其中写入获取枚举类的方法
请勿盗版,转载请加上出处http://blog.csdn.net/yanlintao1
class Student extends Zend_Db_Table{
protected $_name ='student';
protected $_primary ='id';
function getPartyEnum($enumname){
//适配器并获取数据
$db = $this->getAdapter();
$db->query("SET NAMES GBK");
$sql = $db->quoteInto('SHOW COLUMNS FROM student LIKE ?',$enumname);
$res = $db->query($sql)->fetchAll();
//对得到的枚举类进行处理
//得到枚举类字符串
$enum = $res [0] ['Type'];
//以前面的(分成两个数组
$enum_arr = explode ( "(",$enum );
//将第二个数组赋给变量,其实第一个为空数组
$enum = $enum_arr [1];
//以后面的(分成两个数组
$enum_arr = explode ( ")",$enum );
//将第一个数组赋给变量,其实第二个为空数组
$enum = $enum_arr [0];
//以逗号为分界点将得到的字符串分界成N个数组
$enum_arr = explode(',',$enum);
//将每个元素的单引号变成空
for($i=0;$i
$enum_arr[$i] = str_replace("'","",$enum_arr[$i]);
}
return $enum_arr;
}
}
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn