'SET NAMES utf8']); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); } catch(PDOException $e) { trigger_error($e->getMessage()); } // Get total blocks $query = $db->query('SELECT COUNT(*) AS `total` FROM `block`'); $blocksTotal = $query->fetch()['total']; // Get total users $query = $db->query('SELECT COUNT(*) AS `total` FROM `user`'); $usersTotal = $query->fetch()['total']; // Get stats $query = $db->query('SELECT YEAR(FROM_UNIXTIME(`time`)) AS `year`, MONTH(FROM_UNIXTIME(`time`)) AS `month`, COUNT(`block`.`blockId`) AS `blocks`, SUM((SELECT COUNT(`user`.`userId`) FROM `user` WHERE `user`.`blockId` = `block`.`blockId` GROUP BY `user`.`blockId`)) AS `users` FROM `block` GROUP BY `year`, `month` ORDER BY `year`, `month` '); $stats = $query->fetchAll(); ?>