我想打印一個查詢的所有結果,但出於某種原因,我得到以下錯誤:致命錯誤:調用成員函數fetch()布爾在H:\ Some-Location \線X打印PDO查詢結果
這是我的代碼:
<?php
$query = "SELECT adID FROM given WHERE toUser = :userid";
$query_params = array(':userid' => $_SESSION['user']['ID']);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
echo "Failed to run query: " . $ex->getMessage();
}
while ($row = $result->fetch(PDO::FETCH_ASSOC))
{
echo $row['adID'];
}
?>
有什麼不對?