我对PDO很陌生,我想弄清楚如何让它与PDO一起工作。我让它与MYSQL一起工作,我可能混淆了PDO是如何工作的。我得到了一个空白页,任何想法,我可以如何去获得所有的结果收到的记录。我看到了关于PDO的教程,但是当我这样做时,它是针对带有数组的单个记录的。
<?php
require_once("../db_connect.php");
$stmt = $db->prepare ("SELECT * FROM requests WHERE status='Received'");
echo"Received Requests";
echo "<br><br>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
echo("<table bgcolor=F2F2F2 width=1080 border='2'>");
echo("<br><tr><th>Id</th><th>Update</th><th>LanID</th><th>Name</th><th>Location</th><th>Manager</th><th>request</th><th>Description</th><th>request_comments</th><th>Status</th><th>Comments</th><th>Completed User</th><th>Completed Date</th></tr>");
echo("<tr>");
echo "<td>". $row['id'] . "</td>"
."<td><a href='../update.php?id=" . $row['id'] . "'>Update</a></td>"
."<td>" . $row['lanId'] . "</td> "
. "<td>". $row['name'] . "</td>"
. "<td>". $row['department'] . "</td>"
. "<td>" . $row['manager'] . "</td>"
. "<td>" . $row['request'] ."</td>"
. "<td>" . $row['request_description'] ."</td>"
. "<td>" . $row['request_comments'] ."</td>"
. "<td>" . $row['status'] ."</td>"
. "<td>" . $row['comments'] ."</td>"
. "<td>" . $row['compUser'] ."</td>"
. "<td>" . $row['compDt'] ."</td>";
echo '</tr>';
}
echo("</table>");
?>
<html>
<head>
<meta http-equiv="refresh" content="5" >
<title>
</title>
</head>
<body background="../images/background.jpg">
</body>
</html>db_connect.php
<?php
$db_host = "localhost";
$db_username = "root";
$db_pass = "";
$db_name = "systems_requests";
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
?>
发布于 2014-11-06 15:01:48
你忘了执行你准备好的陈述。
请在使用$stmt->execute ()之前使用$stmt->fetch ()
另外,请取如下所示:
$requests = $stmt->fetch (PDO::FETCH_ASSOC);
foreach ($requests as $request) {
echo $request["whateverKeyYouWant"];
}https://stackoverflow.com/questions/26782138
复制相似问题