diff options
author | Thomas Lange <code@nerdmind.de> | 2017-09-02 15:19:59 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2017-09-02 15:19:59 +0200 |
commit | c503f83d169fe15e10e2d97fd4ece9cdc884e436 (patch) | |
tree | 681ed769e047a300a9b5a8bf9422caac95222e04 /admin | |
parent | e12cea77d8dabaf8bcaa30a0efb6ad8be0a15260 (diff) | |
download | blog-c503f83d169fe15e10e2d97fd4ece9cdc884e436.tar.gz blog-c503f83d169fe15e10e2d97fd4ece9cdc884e436.tar.xz blog-c503f83d169fe15e10e2d97fd4ece9cdc884e436.zip |
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.
Diffstat (limited to 'admin')
-rw-r--r-- | admin/index.php | 16 |
1 files changed, 10 insertions, 6 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)); } #=============================================================================== |