This model is built in models, in which the method of obtaining an enumeration class is written
Do not pirated, reproduced please add the source Http://blog.csdn.net/yanlintao1
Class Student extends zend_db_table{
protected $_name = ' student ';
Protected $_primary = ' id ';
function Getpartyenum ($enumname) {
Adapter and get the data
$db = $this->getadapter ();
$db->query ("SET NAMES GBK");
$sql = $db->quoteinto (' SHOW COLUMNS from student?
', $enumname);
$res = $db->query ($sql)->fetchall ();
Processing of the resulting enumeration class
Get the enumeration class string
$enum = $res [0] [' Type '];
Used to be (divided into two arrays
$enum _arr = Explode ("(", $enum);
Assigns the second array to a variable, in fact the first is an empty array
$enum = $enum _arr [1];
In the back (divided into two arrays
$enum _arr = Explode (")", $enum);
Assigns the first array to a variable, in fact the second is an empty array
$enum = $enum _arr [0];
Dividing the resulting string into n arrays by a comma
$enum _arr = Explode (', ', $enum);
Turns the single argument of each element into an empty
for ($i =0; $i <count ($enum _arr); $i + +) {
$enum _arr[$i] = str_replace ("'", "", $enum _arr[$i]);
}
return $enum _arr;
}
}
The
Zend Framework obtains and converts data from a database enum class enum to an array