Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

There is pdostatement.rowcount , but it doesn't work right for SELECT, so use the following instead.

http://stackoverflow.com/questions/25034652/php-pdo-rowcount-return-wrong-result

$query = $db->prepare("

  SELECT COUNT(*) FROM table
  WHERE
       whatever
 ");

$query->execute();

$result = $query->fetchColumn();

if ($result > 5)
{
echo "Result is greater than 5";
}
else
{
echo "Result is less than 5";
}
?>

  • No labels

1 Comment