-2

希望有人能给我一些帮助...我正在使用 PDO 从数据库中获取一些数据,但是每次脚本运行时它都会返回没有错误但不会显示所需的数据,我知道数据我正在寻找也在那里..任何帮助将不胜感激,这就是我目前所拥有的,谢谢。

$db = new PDO('sqlite:C:\\xampp\\htdocs\\Utils\\PDF_Utils\\PDF2Word\\details.sqlite');

    echo "<table border=1>";
    echo "<tr><td>FileID</td>
              <td>File Name</td>
              <td>Email From</td>
              <td>CC</td> <td>Subject</td>
              <td>File Size</td></tr>";


              $contents = $db->prepare("SELECT * FROM details WHERE fileName = 
                         '$yourFileName'");
              $contents->execute();

                   foreach($contents as $row) {
                        echo "<tr><td>" . $row['FileID'] . "</td>";
                        echo "<td>" . $row['fileName'] . "</td>";
                        echo "<td>" . $row['emailFrom'] . "</td>";
                        echo "<td>" . $row['CC'] . "</td>";
                        echo "<td>" . $row['subject'] . "</td>";
                        echo "<td>" . $row['fileSize'] . "</td></tr>";
                    }
                    echo "</table>";
4

3 回答 3

0
$stmt = $db->prepare("SELECT * FROM details WHERE fileName = ?"); 
$stmt->execute(array($yourFileName));
$contents = $stmt->fetchAll();

其余的都是一样的

于 2013-05-13T10:25:58.870 回答
-1

在 $yourFileName 周围加上括号作为 {$yourFileName}

于 2013-05-13T10:24:49.143 回答
-1

在准备语句时使用占位符,然后执行传递参数的查询,如下所示:

$contents = $db->prepare("SELECT * FROM details WHERE fileName = ?");
$contents->execute(array($yourFileName));

然后使用 FETCH_ASSOC 获取结果:

while($row = $contents->fetch(PDO::FETCH_ASSOC)){
     //your code here;
}
于 2013-05-13T10:23:47.713 回答