Re: get emum values

From: Date: Sun, 24 Feb 2002 19:02:15 +0000
Subject: Re: get emum values
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-86002@lists.php.net to get a copy of this message
On Monday 25 February 2002 02:59, Nick Wilson wrote: > Hi all > Which php function can I use to get the emum values from a mysql db > table? I remember doing this once before but I've been looking at the > manual and just can't remember how I did it? Not sure whether there is a built-in function for doing so. But here's something I prepared earlier: #=========================================================== # create_list_from_ENUM #----------------------------------------------------------- # Returns array [enum vals] # # Arguments # --------- # # $dbh : a $dbh object defined in class.DBI.inc # $table : the table to get the ENUM values from # $column : the column containing the ENUM values # #=========================================================== function create_list_from_ENUM($dbh, $table, $column) { $sth = $dbh->prepare("SHOW COLUMNS FROM $table LIKE '$column'"); if ($sth) { $sth->execute(); while ($row = $sth->fetchrow_hash()) { ereg("('(.*)')", $row[1], $temp); $array = explode( "','", $temp[2] ); while (list ($key, $val) = each ($array)) { $return[] = "$val"; } } } return $return; } -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* Lies! All lies! You're all lying against my boys! -- Ma Barker */

« previous php.general (#86002) next »