From a29d3b60dce49dbc8d1b118409c6809ffa480aa3 Mon Sep 17 00:00:00 2001 From: kokororin Date: Tue, 5 Sep 2017 12:10:36 +0800 Subject: [PATCH] improve: #14 --- Access_Core.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Access_Core.php b/Access_Core.php index 792631e..5b6593b 100644 --- a/Access_Core.php +++ b/Access_Core.php @@ -178,14 +178,17 @@ class Access_Core $start = strtotime(date("{$time} {$i}:00:00")); $end = strtotime(date("{$time} {$i}:59:59")); // "SELECT DISTINCT ip FROM {$this->table} {$where} AND `time` BETWEEN {$start} AND {$end}")); + $subQuery = $this->db->select('DISTINCT ip')->from('table.access_log') + ->where("time >= ? AND time <= ?", $start, $end); + if (method_exists($subQuery, 'prepare')) { + $subQuery = $subQuery->prepare($subQuery); + } $this->overview['ip'][$day]['hours'][$i] = intval($this->db->fetchAll($this->db->select('COUNT(1) AS count') - ->from('(' . $this->db->select('DISTINCT ip')->from('table.access_log') - ->where("time >= {$start} AND time <= {$end}") . ') AS tmp'))[0]['count']); + ->from('(' . $subQuery . ') AS tmp'))[0]['count']); $this->overview['ip'][$day]['total'] += $this->overview['ip'][$day]['hours'][$i]; // "SELECT DISTINCT ip,ua FROM {$this->table} {$where} AND `time` BETWEEN {$start} AND {$end}")); $this->overview['uv'][$day]['hours'][$i] = intval($this->db->fetchAll($this->db->select('COUNT(1) AS count') - ->from('(' . $this->db->select('DISTINCT ip,ua')->from('table.access_log') - ->where("time >= {$start} AND time <= {$end}") . ') AS tmp'))[0]['count']); + ->from('(' . $subQuery . ') AS tmp'))[0]['count']); $this->overview['uv'][$day]['total'] += $this->overview['uv'][$day]['hours'][$i]; // "SELECT ip FROM {$this->table} {$where} AND `time` BETWEEN {$start} AND {$end}")); $this->overview['pv'][$day]['hours'][$i] = intval($this->db->fetchAll($this->db->select('COUNT(1) AS count')