i have a problem to use pdo
for get COUNT(*)
.
(...)
public function getRowCount($sql, $bin = null)
{
$a = $this->conn->prepare($sql);
if (!is_null($bin)) {
foreach ($bin as $i => $val) {
$a->bindParam(":$i", $val);
}
}
$a->execute();
return $a->fetchColumn();
}
(...)
If I use this, it works for me :
// $obj = new class()
echo $obj->getRowCount("SELECT COUNT(*) FROM `table_name` WHERE `a`=:a", [
'a' => 'ABC'
]);
// 1 or 2 and ...
But it doesn't work with two conditions :
// $obj = new class()
echo $obj->getRowCount("SELECT COUNT(*) FROM `table_name` WHERE `a`=:a AND `b`=:b", [
'a' => 'ABC',
'b' => 'DEF'
]);
// only 0