Posted By

ginoplusio on 12/12/08


Tagged

mysql php enum set values


Versions (?)

mysql php get enum values


 / Published in: SQL
 

URL: http://www.barattalo.it/2010/01/19/php-to-get-enum-set-values-from-mysql-field/

  1. FUNCTION set_and_enum_values( $table , $field ){
  2. $query = "SHOW COLUMNS FROM `$table` LIKE '$field'";
  3. $result = mysql_query( $query ) OR die( 'Error getting Enum/Set field ' . mysql_error() );
  4. $row = mysql_fetch_array($result);
  5. IF(stripos(".".$row[1],"enum(") > 0) $row[1]=str_replace("enum('","",$row[1]);
  6. else $row[1]=str_replace("set('","",$row[1]);
  7. $row[1]=str_replace("','","\n",$row[1]);
  8. $row[1]=str_replace("')","",$row[1]);
  9. $ar = split("\n",$row[1]);
  10. FOR ($i=0;$i<count($ar);$i++) $arOut[str_replace("''","'",$ar[$i])]=str_replace("''","'",$ar[$i]);
  11. RETURN $arOut ;
  12. }

Report this snippet  

You need to login to post a comment.