示例#1
0
/**
 * returns an array containing the possible values of an enum field
 *
 * @param string tablename
 * @param string fieldname
 */
function get_enums($table, $field)
{
    // retrieving the properties of the table. Each line represents a field :
    // columns are 'Field', 'Type'
    $result = pwg_query('desc ' . $table);
    while ($row = pwg_db_fetch_assoc($result)) {
        // we are only interested in the the field given in parameter for the
        // function
        if ($row['Field'] == $field) {
            // retrieving possible values of the enum field
            // enum('blue','green','black')
            $options = explode(',', substr($row['Type'], 5, -1));
            foreach ($options as $i => $option) {
                $options[$i] = str_replace("'", '', $option);
            }
        }
    }
    pwg_db_free_result($result);
    return $options;
}
示例#2
0
/**
 * Returns an array containing the possible values of an enum field.
 *
 * @param string $table
 * @param string $field
 * @return string[]
 */
function get_enums($table, $field)
{
    $result = pwg_query('DESC ' . $table);
    while ($row = pwg_db_fetch_assoc($result)) {
        if ($row['Field'] == $field) {
            // parse enum('blue','green','black')
            $options = explode(',', substr($row['Type'], 5, -1));
            foreach ($options as $i => $option) {
                $options[$i] = str_replace("'", '', $option);
            }
        }
    }
    pwg_db_free_result($result);
    return $options;
}