Created
May 9, 2012 14:59
-
-
Save a1phanumeric/2645144 to your computer and use it in GitHub Desktop.
Get array from ENUM def in MySQL yo x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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