The rowCount()
method of PDO always returns zero value, even if there's results, according to:
count($sth->fetch(PDO::FETCH_ASSOC)) > 1
Fromt this PHP code:
$_user = "a";
$_pass = "b";
$query = "select user,password from login where user = :user and password = :pass";
$conn = new PDO("sqlite:" .Config::$db_file);
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$sth = $conn->prepare($query);
$sth->bindParam(':user', $_user);
$sth->bindParam(':pass', $_pass);
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);
echo "rowCount() = ",$sth->rowCount(),"\n";
echo 'count($result) = ', count($result), "\n";
print_r($result);
I get:
rowCount() = 0 count($result) = 2 Array ( [user] => a [password] => b )
How to fix this?