Zend Framework gets and converts data from a database enum class enum to an array

Source: Internet
Author: User
Tags explode zend zend framework

Create a model in which you write a method that gets the enumeration class


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 like ', $enumname);
$res = $db->query ($sql)->fetchall ();
Processing of the resulting enumeration class
Get the enumeration class string
$enum = $res [0] [' Type '];
With the preceding (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);
Turn single quotation marks for each element into empty
for ($i =0; $i <count ($enum _arr); $i + +) {
$enum _arr[$i] = str_replace ("'", "", $enum _arr[$i]);

}
return $enum _arr;

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.