php - PDO 不会执行,但在 phpmyadmin 中可以正常工作
问题描述
我有以下代码:
<?php
// ... other code...
$prepared_statement = <<< MYSQL
SELECT `Organization`, `City`, `Region`, `Country`, `Contact`, `Manager`, `Description`
FROM `businesses`
WHERE (
(`Organization` LIKE ? OR `City` LIKE ? OR `Region` LIKE ? OR `Country` LIKE ? OR `Manager` LIKE ? OR `Description` LIKE ?)
AND
(`Organization` LIKE ? OR `City` LIKE ? OR `Region` LIKE ? OR `Country` LIKE ? OR `Source` LIKE ? OR `Description` LIKE ?)
)
ORDER BY `Timestamp`;
MYSQL;
$value_list = ["Missouri","Missouri","Missouri","Missouri","Missouri","Missouri","US","US","US","US","US","US"]; // Populated through some passed in parameters, simplified to a known result here for simplicity sake.
try {
$query = $this_pdo -> prepare();
$query->execute($value_list); // <-- This line is where it breaks, but doesn't trigger the catch and doesn't output any error. Doing it in phpmyadmin returns 1 result.
$result = $query->fetchAll(PDO::FETCH_ASSOC);
return $result;
} catch (PDOException $e) {
return ["A database problem has occurred: " . $e->getMessage()];
}
我试过直接在数据库中运行查询,替换“?” 用数组中的值标记,它可以工作。但执行不?
解决方案
发现了我的问题。简单的错误......忘记将我准备好的语句放入准备调用中。
*pdo->prepare()
如果它为空,则不会返回错误,尽管它是空的,但后续执行调用会失败。*
推荐阅读
- javascript - 在 Mapboxgl.js 的弹出窗口中添加一个按钮
- reactjs - 在执行子组件之前等待对象可用
- amazon-ec2 - 具有 IOT 数据的可扩展超级账本 v1.4 的应用程序架构
- javascript - 如何将 HTML 与 Python 结合起来?
- testing - 测试注册表 - 问题是关于使用空格键
- reactjs - 在 api 中修改 Fetch 结果
- javascript - Ajax 成功函数和变量作用域
- ios - 在另一个模块对共享服务执行任务后,如何通知 VIPER 模块需要重新加载?
- java - 如何使用 Java 中的 Kotlin 函数?
- c - Valgrind 根据未初始化的值报告条件跳转或移动,但我不明白为什么