From c503f83d169fe15e10e2d97fd4ece9cdc884e436 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sat, 2 Sep 2017 15:19:59 +0200 Subject: Some code optimizations has been made in admin/index.php to prevent duplicate definitions of the same SQL query. Additionally, the default database fetch mode was changed to FETCH_ASSOC. --- admin/index.php | 16 ++++++++++------ core/application.php | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/admin/index.php b/admin/index.php index 1cddb8c..7e0b838 100644 --- a/admin/index.php +++ b/admin/index.php @@ -14,13 +14,17 @@ require '../core/application.php'; # TRY: PDOException #=============================================================================== try { - $LastPageStatement = $Database->query(sprintf('SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1', Page\Attribute::TABLE)); - $LastPostStatement = $Database->query(sprintf('SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1', Post\Attribute::TABLE)); - $LastUserStatement = $Database->query(sprintf('SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1', User\Attribute::TABLE)); + $execute = 'SELECT id FROM %s ORDER BY time_insert DESC LIMIT 1'; - $PageCountStatement = $Database->query(sprintf('SELECT COUNT(*) FROM %s', Page\Attribute::TABLE)); - $PostCountStatement = $Database->query(sprintf('SELECT COUNT(*) FROM %s', Post\Attribute::TABLE)); - $UserCountStatement = $Database->query(sprintf('SELECT COUNT(*) FROM %s', User\Attribute::TABLE)); + $LastPageStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE)); + $LastPostStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE)); + $LastUserStatement = $Database->query(sprintf($execute, User\Attribute::TABLE)); + + $execute = 'SELECT COUNT(*) FROM %s'; + + $PageCountStatement = $Database->query(sprintf($execute, Page\Attribute::TABLE)); + $PostCountStatement = $Database->query(sprintf($execute, Post\Attribute::TABLE)); + $UserCountStatement = $Database->query(sprintf($execute, User\Attribute::TABLE)); } #=============================================================================== diff --git a/core/application.php b/core/application.php index 7ba66fe..a575f9d 100644 --- a/core/application.php +++ b/core/application.php @@ -74,7 +74,7 @@ try { $Language = Application::getLanguage(); $Database = Application::getDatabase(); - $Database->setAttribute($Database::ATTR_DEFAULT_FETCH_MODE, $Database::FETCH_OBJ); + $Database->setAttribute($Database::ATTR_DEFAULT_FETCH_MODE, $Database::FETCH_ASSOC); $Database->setAttribute($Database::ATTR_ERRMODE, $Database::ERRMODE_EXCEPTION); } @@ -104,7 +104,7 @@ if(Application::get('CORE.SEND_304') === TRUE AND !defined('ADMINISTRATION')) { #=========================================================================== # Define HTTP ETag header identifier #=========================================================================== - $HTTP_ETAG_IDENTIFIER = md5(implode($Statement->fetch(PDO::FETCH_ASSOC))); + $HTTP_ETAG_IDENTIFIER = md5(implode($Statement->fetch())); #=========================================================================== # Send ETag header within the HTTP response -- cgit v1.2.3