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()为空,则不会返回错误,尽管它为空,但后续执行调用失败。

相关内容

最新更新