Skip to content

Instantly share code, notes, and snippets.

@a1phanumeric
Created May 9, 2012 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a1phanumeric/2645144 to your computer and use it in GitHub Desktop.
Save a1phanumeric/2645144 to your computer and use it in GitHub Desktop.
Get array from ENUM def in MySQL yo x
<?php
// Change the following:
// TABLE_NAME = the name of your table
// COLUMN_NAME = the name of your column with an enum type
$result = mysql_query("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TABLE_NAME' AND COLUMN_NAME = 'COLUMN_NAME'");
if(mysql_num_rows($result) == 1){
$remove = array('enum(', ')', "'");
$row = mysql_fetch_assoc($result);
$array = explode(',', str_replace($remove, '', $row['COLUMN_TYPE']));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment