I have an access log database with more than 110,000 records.
I run the next query on my console:
SELECT COUNT(`remote_host`), `remote_host` FROM `access_log`
GROUP BY `remote_host` HAVING COUNT(`remote_host`) > 99
ORDER BY COUNT(`remote_host`) DESC
I have that result. Mysql query result
With 143 records.
But when I execute a PHP code with the same query, the result is some diferent with 174 records (??). Query with PHP
And the first record have the next values : 89.248.174.171, 14160
2365 vs 14160 !!??
The second result it's OK. But... the all next results are diferent too !!
The PHP code it's simple:
$q_1 = "SELECT COUNT(`remote_host`), `remote_host` FROM `access_log` GROUP BY `remote_host` HAVING COUNT(`remote_host`) > 99 ORDER BY COUNT(`remote_host`) DESC ;";
$aItems = doQuery($con, $q_1);
echo count($aItems)."<br/>";
var_dump($aItems);
Function doQuery:
function doQuery($con, $query) {
$result = mysqli_query($con, $query);
$arr = array();
if ($result) {
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
$arr[] = $row;
mysqli_free_result($result);
}
return $arr;
}
Just define a COUNT by using AS in PHP
SELECT COUNT(`remote_host`) AS RHOST, `remote_host` FROM `access_log`
GROUP BY `remote_host` HAVING COUNT(`remote_host`) > 99
ORDER BY COUNT(`remote_host`) DESC