note 77960 added to ref.mysql
| From: | janturon at email dot cz | Date: | Fri, 21 Sep 2007 12:25:03 +0000 |
| Subject: | note 77960 added to ref.mysql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130659@lists.php.net to get a copy of this message | ||
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 '
}
----
Server IP: 147.32.160.17
Probable Submitter: 81.2.196.33
----
Manual Page -- http://www.php.net/manual/en/ref.mysql.php
Edit -- https://master.php.net/note/edit/77960
Del: integrated -- https://master.php.net/note/delete/77960/integrated
Del: useless -- https://master.php.net/note/delete/77960/useless
Del: bad code -- https://master.php.net/note/delete/77960/bad+code
Del: spam -- https://master.php.net/note/delete/77960/spam
Del: non-english -- https://master.php.net/note/delete/77960/non-english
Del: in docs -- https://master.php.net/note/delete/77960/in+docs
Del: other reasons-- https://master.php.net/note/delete/77960
Reject -- https://master.php.net/note/reject/77960
Search -- https://master.php.net/manage/user-notes.php