小弟我照著以前的方法寫php,但是出現了之前沒出現過的錯誤,請各位大大解惑。
<?php
require_once("db/db.php");
?>
<?php
$sql = "select Month from a4";
$result = $project->query($sql);
$row_cnt = $result->rowCount();
$row = $result->fetchALL(PDO::FETCH_ASSOC);
echo " <font color= SlateGrey size='5pt'>全部資料<br><br><br></font>";
echo "<table border='1' width='1200' height='90' align='center' >";
echo "<tr>";
echo "<th>num</th>";
echo "<th>name</th>";
echo "<th>price</th>";
echo "</tr>";
foreach($row as $row2){
echo "<tr>";
foreach($row2 as $key => $str){
echo "<td>".$str."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
<?php
require_once("db/db.php");
?>
<?php
$sql = "select Month from a4";
$result = $project->query($sql);
錯誤訊息很清楚啊 你正在null上call query()
你看看你的code 沒有宣告$project 他是null
少了一行建立db連接的code