Advertisement
slovacus

getEnumSetValues

Jul 28th, 2011
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. function getEnumSetValues( $table , $field ){
  2.     // get an array of the allowed values
  3.     // of the enum or set $field of $table
  4.     $query = "SHOW COLUMNS FROM `$table` LIKE '$field'";
  5.     $result = mysql_query( $query ) or die( 'error getting enum field ' . mysql_error() );
  6.     $row = mysql_fetch_array($result);
  7.     if(stripos(".".$row[1],"enum(") > 0) $row[1]=str_replace("enum('","",$row[1]);
  8.         else $row[1]=str_replace("set('","",$row[1]);
  9.     $row[1]=str_replace("','","\n",$row[1]);
  10.     $row[1]=str_replace("')","",$row[1]);
  11.     $ar = split("\n",$row[1]);
  12.     for ($i=0;$i<count($ar);$i++) $arOut[str_replace("''","'",$ar[$i])]=str_replace("''","'",$ar[$i]);
  13.     return $arOut ;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement