Place the setFetchMode above your query (select * from data).
You need to do the configuration before executing the query.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Data is not fetching from db and shows error which is "Fatal error: Uncaught Error: Call to a member function setFetchMode() on bool in ...\practice.php:9 Stack trace: #0 {main} thrown in ...\practice.php on line 9"
code:
<?php
try{
$conn = new PDO("mysql: host = localhost; dbname = php_crud", 'root', '');
$pdo = $conn->query("SELECT * FROM data");
$pdo->setFetchMode(PDO:: FETCH_ASSOC);
while($row = $pdo->fetch()) {
echo $row['email'] . "<br>";
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
?>
Please or to participate in this conversation.