I have this snippet of code that completely screws up when I run it. It doesn’t even throw an exception. It just causes a server error.
try {
$stmt = $this->database->prepare(
"SELECT * FROM news_posts");
$result = $stmt->execute();
$array = $result->fetch(PDO::FETCH_ASSOC);
print_r($array);
} catch (PDOException $e) {
echo "error?";
}
PDOStatement::execute()doesn’t return its results; you callfetchon the query.You could also shorten that to
query(), since you’re not adding any parameters: