note 20857 deleted from function.mysql-fetch-field by danbrown

From: Date: Sat, 20 Jun 2009 02:19:49 +0000
Subject: note 20857 deleted from function.mysql-fetch-field by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157164@lists.php.net to get a copy of this message
Note Submitter: justin at quadmyre dot com ---- Same problem, slightly different solution. $result = mysql_query("DESCRIBE tablename"); # or SHOW COLUMNS FROM # or SHOW FIELDS FROM then loop: $row = mysql_fetch_array($result); # row is mysql type, in format "int(11) unsigned zerofill" # or "enum('cheese','salmon')" etc. ereg('^([^ (]+)(\((.+)\))?([ ](.+))?$',$row['Type'],$fieldTypeSplit); # split type up into array $fieldType = $fieldTypeSplit[1]; # eg 'int' for integer. $fieldFlags = $fieldTypeSplit[5]; # eg 'binary' or 'unsigned zerofill'. $fieldLen = $fieldTypeSplit[3]; # eg 11, or 'cheese','salmon' for enum. You might then like to: if ($fieldType=='enum' or $fieldType=='set') $fieldLen = split("','",substr(1,-1,$fieldLen)); So for enum or set types, $fieldLen becomes an array of possible values. Hope that helps someone out there...

« previous php.notes (#157164) next »