Jump to content

[SOLVED] Finding enum options of a column in a mysql database


redbrad0

Recommended Posts

I know I can run SHOW CREATE TABLE TableName but it just outputs the following info

 

CREATE TABLE `TableName` ( `Table_ID` int(11) unsigned NOT NULL auto_increment, `Table_Type` enum('Promoter','Media','Corporate') NOT NULL default 'Promoter', PRIMARY KEY (`Table_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1

 

How can I just return the enum values in red?

 

 

Thank you for the reply. For reference for anyone else that might find this thread, here is what I am using.

 

function getEnumOptions($table, $field) {
   $finalResult = array();

   if (strlen(trim($table)) < 1) return false;
   $query  = "show columns from $table";
   $result = mysql_query($query);
   while ($row = mysql_fetch_array($result)){
        if ($field != $row["Field"]) continue;
        //check if enum type
        if (ereg('enum.(.*).', $row['Type'], $match)) {
            $opts = explode(',', $match[1]);
            foreach ($opts as $item)
                $finalResult[] = substr($item, 1, strlen($item)-2);
        }
        else
                return false;
   }
   return $finalResult;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.