我试图将其转换为使用$wpdb类。它将返回所有可能的枚举,我不得不使用这个$wpdb,因为mysql\\u查询给了我奇怪的错误(未选择数据库)代码如下
function getEnumValues($table, $field)
{
$enum_array = array();
$query = \'SHOW COLUMNS FROM `\' . $table . \'` LIKE "\' . $field . \'"\';
$result = mysql_query($query);
if($result === FALSE) {
die(mysql_error()); }
$row = mysql_fetch_row($result);
preg_match_all(\'/\\\'(.*?)\\\'/\', $row[1], $enum_array);
if(!empty($enum_array[1]))
{
//Shift array keys to match original enumerated index in MySQL (allows for use of index values instead of strings)
foreach($enum_array[1] as $mkey => $mval) $enum_fields[$mkey+1] = $mval;
return $enum_fields;
}
else
return array(); // Return an empty array to avoid possible errors/warnings if array is passed to foreach() without first being checked with !empty().
}
之后,我必须使用此代码段来读取它们
<?php
$enums = getEnumValues("property", "form_field_type");
foreach($enums as $enum){
echo \'<input type = "radio" name = "form_field_type" value = "\'.$enum.\'">\';
echo \'<label for = "\'.$enum.\'"> \'.$enum.\'</label><br>\';
}
?>