Skip to content

Instantly share code, notes, and snippets.

@dagostoni
Created November 22, 2013 12:09
Show Gist options
  • Save dagostoni/7598930 to your computer and use it in GitHub Desktop.
Save dagostoni/7598930 to your computer and use it in GitHub Desktop.
Get enum indexes from table field using mysql
<?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;
}
@dagostoni
Copy link
Author

Recupera i valori possibili di un campo enum di una tabella.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment