Created
November 22, 2013 12:09
-
-
Save dagostoni/7598930 to your computer and use it in GitHub Desktop.
Get enum indexes from table field using mysql
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 | |
function getEnumIndexes($table, $field){ | |
$enum = array(); | |
$sql = "SHOW COLUMNS FROM ".addslashes($table)." WHERE Field = '".addslashes($field)."'"; | |
$result = mysql_query($sql); | |
if($row = mysql_fetch_assoc($result)){ | |
$string = $row['Type']; | |
$string = preg_replace('/^enum\(|\)$/i', '', $string); | |
$tmp = explode(',', $string); | |
foreach($tmp as $k => $r){ | |
$enum[$k+1] = preg_replace('/^\'|\'$/i', '', $r); | |
} | |
} | |
return $enum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Recupera i valori possibili di un campo enum di una tabella.