note 77960 deleted from ref.mysql by nlopess
| From: | nlopess@php.net | Date: | Fri, 21 Sep 2007 13:36:51 +0000 |
| Subject: | note 77960 deleted from ref.mysql by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-130660@lists.php.net to get a copy of this message | ||
Note Submitter: janturon at email dot cz
----
Could not find a function that lists enum or set values, so here we go:
/**
* @return array [index]=>enum_value; false if table does not exist or column is not enum or set
type
*/
function mysql_col_values($table,$column) {
$table= addslashes($table);
$column= addslashes($column);
$result= mysql_query("SHOW COLUMNS FROM
$table LIKE '$column'");
if(!$result) return false; // table and column not found
list(,$col)= mysql_fetch_array($result);
$ok= preg_match("/(?:enum|set)\(([^)]+)/",$col,$match);
if(!$ok) return false; // column is neither enum, nor set
$result= explode(",",$match[1]);
array_unshift($result,""); // index 0 is reserved to "" in mysql enum/arrays
return array_map(create_function('$k','return substr($k,1,-1);'),$result); //
strip (lead|clos)ing '
}