APD Toronto
asked on
PDO Row count
Hi Experts,
I am trying to get the row count of the query, but the following always return 0
The output is
I change it to count it always return 1 or greater, even with an invalid email.
My output
I am trying to get the row count of the query, but the following always return 0
$email = $_POST['txtEmail'];
$result = '';
$query = "SELECT first_name, archived FROM users ";
$query .= "WHERE email_address = :email";
$db = Database::getDB();
$statement = $db->prepare($query);
$statement->bindValue(':email', $email);
$row_count = $statement->rowCount();
$statement->execute();
$rows = $statement->fetch(PDO::FETCH_ASSOC);
$statement->closeCursor();
print_variable($rows, 'resv');
echo 'count= ' . $row_count;
The output is
========START=========
resv
Array
(
[first_name] => Aleks
[archived] => 0
)
=========END=========
count= 0
I change it to count it always return 1 or greater, even with an invalid email.
$email = $_POST['txtEmail'];
$result = '';
$query = "SELECT first_name, archived FROM users ";
$query .= "WHERE email_address = :email";
$db = Database::getDB();
$statement = $db->prepare($query);
$statement->bindValue(':email', $email);
$row_count = $statement->rowCount();
$statement->execute();
$rows = $statement->fetch(PDO::FETCH_ASSOC);
$statement->closeCursor();
print_variable($rows, 'resv');
// echo 'count= ' . $row_count;
echo 'count= ' . count($rows);
My output
=========START=========
resv
=========END=========
count= 1
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.