gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:15:21 25 4
gpt4 key购买 nike

我正在尝试将枚举值放入 <option value="$enum">$enum</option>但到目前为止还没有任何运气。

我真的不能说为什么,我得到的错误是“可捕获的 fatal error :类 PDOStatement 的对象无法转换为第 58 行 C:\xampp\htdocs\sp-admin\form.php 中的字符串”

第 58 行是 $result = str_replace(array("enum('", "')", "''"), array('', '', "'"), $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 object 不是您期望的结果,而是从中获取结果的 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];

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

关于php - MySQL 查询获取枚举值并将其写入下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21532597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com