基本上,我有一个准备好的pdo语句。它执行但没有结果。这是我的代码:
<?php
require 'config.php';
$query = $_GET['q'];
if ($query==null) {
exit('No query');
}
$sql = "SELECT * FROM `uploads_public` WHERE Title =:query ";
if($stmt = $pdo->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bindParam(":query", $query, PDO::PARAM_STR);
// Attempt to execute the prepared statement
if($stmt->execute()){
echo "Your search $query has the following results:<br>";
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($results);
} else{
echo "Something went wrong. Please try again later. <br>"; print_r($stmt->errorInfo());
}
// Close statement
unset($stmt);
unset($pdo);
}
else{
echo "No input";
}
我确定存在一个表uploads_public
,该行Title
,并且至少有五列的值为first
。该文件的名称为{{1} }
但是当我运行脚本dbselect.php
时,得到的结果是:
localhost/dbselect.php?q=first
仅此而已,它不显示结果,它执行但不显示实际结果。
我知道我做错了事,但我只是不能把手放在上面。请帮忙。
答案 0 :(得分:1)
您尚未输出结果。
echo $json;
或者:
echo json_encode($results);