Get enum values from MySQL

by Ramya 2008-12-05 13:02:49

Get enum values from MySQL:

If you want to display enum values from mysql then use the following query,

$query = "SHOW COLUMNS FROM table_name LIKE 'field'";


it will result,

sql.gif

then extract the enum values using,

$result = mysql_query($query,$link);
$row1 = mysql_fetch_array( $result , MYSQL_NUM );
$regex = "/'(.*?)'/";
preg_match_all( $regex , $row1[1], $enum_array );
$enum_fields = $enum_array[1];


Here $regex extracts the values whichever is in between single quotes enum('value1','value2','value3')
ie., it extracts only value1value2value3.



Tagged in:

1434
like
0
dislike
0
mail
flag

You must LOGIN to add comments