0
Hello,
I’m a beginner in PDO connections in PHP and my first select
I am facing the following error:
Fatal error: Call to a member function rowCount() on boolean in C:\MAMP\htdocs\samples\pdo\conexao.php on line 12
Follows my code:
<?php
try {
$pdo = new PDO("mysql:host=localhost;dname=dashboard","root","root");
} catch(PDOException $e) {
echo '<b style="color:red">'.$e->getMessage().'</b>';
}
$buscarUsuario = $pdo->query("SELECT * FROM usuarios");
$buscarUsuario->rowCount(); //linha 12
I checked the connection and also the table name, there is nothing wrong, I looked for possible solutions to this my problem here on the forum and nothing that solved, and when giving var_dump
users, it returns me bool(false)
.
If by chance the query is not executed,
$pdo->query()
returns aboolean == false
– MarceloBoni
Add
$buscarUsuario = $pdo->query("SELECT * FROM usuarios");
within thetry {
and makeif($buscarUsuario){ $buscarUsuario->rowCount(); }
– MarceloBoni
@Marceloboni but query not running??
– João Vitor
If it had been executed, it would not return bool(false), do what I recommended and see which error was given in the query
– MarceloBoni