note 33596 deleted from function.mysql-field-type by didou
| From: | didou@php.net | Date: | Thu, 03 Jul 2003 08:10:25 +0000 |
| Subject: | note 33596 deleted from function.mysql-field-type by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-51401@lists.php.net to get a copy of this message | ||
Note Submitter: Nikolaj
----
There's a small "bug" in the following line (submitted by "e at eikimartinson
dot c0m"):
$values = split(",", preg_replace("/'/", "", $matches[1]));
It doesn't allow the user to specify an , inside one of the values.
Instead use something like:
$values = preg_split("/','/", substr($matches[1], 1, -1));
The entire script will then be:
$result = mysql_query("SHOW FIELDS FROM database_name.table_name LIKE
'enum_column_name'");
$row = mysql_fetch_array($result);
if (preg_match("/^enum\((.*)\)$/", $row['Type'], $matches)) {
$values = preg_split("/','/", substr($matches[1], 1, -1));
}
An alternative way, is to "remove" the first and last ', directly in the "if
(preg_match ..." :-)