Is there some sort of conflict with rowCount? I understand that the sentence is fine, and I am using PDO, which did not give me any problems before
The field in the database is VARCHAR2.
I attach my code:
$user = 'pepito'
$con = connection();
$statement = $con->prepare("SELECT name FROM usuarios WHERE name = :usu");
$statement->bindParam(':usu', $user);
$statement->execute();
//Con este contador, devielve 1 si encuentra el usuario
$contador = $statement->rowCount();
The counter returns 0, when it should return 1.
A call to
rowCount()
after a querySELECT
may return 0 instead of the number of records fetched depending on the database.As can be read in the official documentation of
PDOStatement::rowCount()
:Therefore, you should not rely on it to know the number of records obtained, you must use the SQL query
COUNT
or obtain all the records withPDOStatement::fetchAll()
and do acount()
to the result obtained.