How can I get count(*) or SUM(col1) using PHP PDO
I have used
$STH_SELECT = $dbh->prepare("SELECT count(*) FROM Table");
$STH_SELECT->execute;
$result = $STH_SELECT->fetchAll;
$Count = $result[0][0];
Is this correct and Is there a better way?
You don't need to use prepared statement when you aren't entering any data into the query.
$STH_SELECT = $dbh->query("SELECT count(*) FROM Table");
$Count = $STH_SELECT->fetchColumn();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With