Zend framework obtains and converts enum-like data in the database to an array.

Source: Internet
Author: User

Create such a model in the model and write the method to obtain the enumeration class.

Please do not pirated, reproduced please add source http://blog.csdn.net/yanlintao1

Class Student extends Zend_Db_Table {
Protected $ _ name = 'student ';
Protected $ _ primary = 'id ';

Function getPartyEnum ($ enumname ){

// Adapter and get data
$ Db = $ this-> getAdapter ();
$ Db-> query ("set names gbk ");
$ SQL = $ db-> quoteInto ('show COLUMNS FROM student LIKE? ', $ Enumname );
$ Res = $ db-> query ($ SQL)-> fetchAll ();
// Process the enumerated classes
// Obtain the enumerated string
$ Enum = $ res [0] ['type'];
// Previous (divided into two Arrays
$ Enum_arr = explode ("(", $ enum );
// Assign the second array to the variable. In fact, the first is an empty array.
$ Enum = $ enum_arr [1];
// The following (divided into two Arrays
$ Enum_arr = explode (")", $ enum );
// Assign the first array to the variable. In fact, the second is an empty array.
$ Enum = $ enum_arr [0];
// The comma-separated string is divided into N arrays.
$ Enum_arr = explode (',', $ enum );
// Empty the single quotes of each element
For ($ I = 0; $ I <count ($ enum_arr); $ I ++ ){
$ Enum_arr [$ I] = str_replace ("'", "", $ enum_arr [$ I]);

}
Return $ enum_arr;

}

}

Related Article

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.