Php MySQL查询以获取枚举值并将其写入下拉列表

Php MySQL查询以获取枚举值并将其写入下拉列表,php,mysql,enums,Php,Mysql,Enums,我正在尝试将枚举的值放入$enum中,但到目前为止没有任何运气 我真的说不出原因,我得到的错误是“可捕获致命错误:类PDOStatement的对象无法转换为C:\xampp\htdocs\sp admin\form.php第58行中的字符串” 第58行是$result=str_replace(数组(“enum(“,”),“,”)”),数组(“,”,”),$result) 这是我的php $query = "SELECT column_type FROM information_schema.co

我正在尝试将枚举的值放入
$enum
中,但到目前为止没有任何运气

我真的说不出原因,我得到的错误是“可捕获致命错误:类PDOStatement的对象无法转换为C:\xampp\htdocs\sp admin\form.php第58行中的字符串”

第58行是
$result=str_replace(数组(“enum(“,”),“,”)”),数组(“,”,”),$result)

这是我的php

$query = "SELECT column_type FROM information_schema.columns
WHERE table_name = 'files' AND column_name = 'cat_page_pos'";
$result = $db->prepare($query);
    $result = str_replace(array("enum('", "')", "''"), array('', '', "'"), $result);
    $arr = explode("','", $result);
    return $arr;
请给我一个提示


提前感谢

您的
$result
对象不是您期望的结果,而是要从中获取结果的PDO语句

在调用
$db->prepare
后,尝试以下操作:

//perform SQL query on DB , since it has only be prepared
$result->execute();
//retrieve results from execution, here you obviously expect to get only one result
$data=$result->fetch();

$coltype=$data[0];

然后,您将找到要处理的字符串(在
$coltype
变量中使用“
enum('xxx','yyy')
”)

请提供$result的打印。我甚至无法尝试并开始计算您要替换的字符串。你能解释一下你想用什么替换什么吗?单引号和双引号的数量使我的大脑死亡。@此处的Humblerat是我的print语句对象([queryString]=>从information_schema.columns中选择column_type,其中table_name='files'和column_name='cat_page_pos'),而不是使用information_schema.columns,尝试使用DESC table_name,这是我现在的数组([column_type]=>enum('0'、'1'、'2'、'3'、'4'、'5')[0]=>enum('0'、'1'、'2'、'3'、'4'、'5')),所以现在我将清理返回的结果并以我需要的方式使用它。