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
*/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php