无法显示已执行的SQL语句的结果

时间:2019-01-30 18:57:13

标签: php mysql sql

基本上,我有一个准备好的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

仅此而已,它不显示结果,它执行但不显示实际结果。

我知道我做错了事,但我只是不能把手放在上面。请帮忙。

1 个答案:

答案 0 :(得分:1)

您尚未输出结果。

echo $json;

或者:

echo json_encode($results);