Mailinglisten-Archive |
Hallo,
ich habe vor kurzem eine Anfrage gestellt zwecks auslese von ENUM - Werten.
Hier sind nun die Funktionen die ich mir zusammengebaut habe:
//////////////////////////////////////////////////////////////////////////
function enum_table($table){
$sql = "SHOW FIELDS FROM $table";
if ($result =
ql_query($sql)){
while ($row= mysql_fetch_array($result)) {
// Wenn Feldtype = ENUM
if(is_int(strpos($row["Type"],"enum"))){
// enum('blah','blub','bläh) => blah','blub','bläh')
$tok = substr($row["Type"],strpos($row["Type"],"'")+1);
// blah','blub','bläh') => blah','blub','bläh
$tok = substr($tok,0,strlen($tok)-2);
// blah','blub','bläh => in mehrdimensionales ARRAY
$enum[$row["Field"]] = explode("','" , $tok);
}
}
}else{
// Fehler
}
return $enum;
}
//////////////////////////////////////////////////////////////////////////
function enum_field($field,$table){
$sql = "SHOW COLUMNS FROM $table LIKE '$field'";
if ($result = mysql_query($sql)){
while ($row= mysql_fetch_array($result)) {
// Wenn Feldtype = ENUM
if(is_int(strpos($row["Type"],"enum"))){
// enum('blah','blub','bläh) => blah','blub','bläh')
$tok = substr($row["Type"],strpos($row["Type"],"'")+1);
// blah','blub','bläh') => blah','blub','bläh
$tok = substr($tok,0,strlen($tok)-2);
// blah','blub','bläh => in ARRAY
$enum = explode("','" , $tok);
}else{
// FEHLER
}
}
}else{
// FEHLER
}
return $enum;
}
//////////////////////////////////////////////////////////////////////////
Vielen Dank an alle,
Tobias.
php::bar PHP Wiki - Listenarchive