diff --git a/library/mysql.php b/library/mysql.php index 7571d9b..f5b3bdf 100644 --- a/library/mysql.php +++ b/library/mysql.php @@ -121,15 +121,6 @@ class MySQL { } // Images - public function getTotalImages() { - - $query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `hostImage`'); - - $query->execute(); - - return $query->fetch()->total; - } - public function getTotalHostImages(int $hostId) { $query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `hostImage` WHERE `hostId` = ?'); @@ -362,15 +353,6 @@ class MySQL { return $query->fetch()->total; } - public function getTotalPages() { - - $query = $this->_db->prepare('SELECT COUNT(*) AS `total` FROM `hostPage`'); - - $query->execute(); - - return $query->fetch()->total; - } - public function getHostPage(int $hostId, int $crc32uri) { $query = $this->_db->prepare('SELECT * FROM `hostPage` WHERE `hostId` = ? AND `crc32uri` = ? LIMIT 1'); diff --git a/library/sphinxql.php b/library/sphinxql.php index ea4bf72..41379d8 100644 --- a/library/sphinxql.php +++ b/library/sphinxql.php @@ -49,6 +49,15 @@ class SphinxQL { return $query->fetchAll(); } + public function getHostPagesTotal() { + + $query = $this->_sphinx->prepare('SELECT COUNT(*) AS `total` FROM `hostPage`'); + + $query->execute(); + + return $query->fetch()->total; + } + public function searchHostPagesTotal(string $keyword) { $query = $this->_sphinx->prepare('SELECT COUNT(*) AS `total` FROM `hostPage` WHERE MATCH(?)'); @@ -66,4 +75,13 @@ class SphinxQL { return $query->fetch()->total; } + + public function getHostImagesTotal() { + + $query = $this->_sphinx->prepare('SELECT COUNT(*) AS `total` FROM `hostImage`'); + + $query->execute(); + + return $query->fetch()->total; + } } diff --git a/public/index.php b/public/index.php index 221af9f..a5dbfb7 100644 --- a/public/index.php +++ b/public/index.php @@ -3,12 +3,12 @@ // Load system dependencies require_once('../config/app.php'); require_once('../library/filter.php'); -require_once('../library/mysql.php'); +require_once('../library/sphinxql.php'); -// Connect database -$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); +// Connect Sphinx search server +$sphinx = new SphinxQL(SPHINX_HOST, SPHINX_PORT); -$totalPages = $db->getTotalPages(); +$totalPages = $sphinx->getHostPagesTotal(); $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the new one...'), $totalPages), sprintf(_('Over %s pages or enter the new one...'), $totalPages), diff --git a/public/search.php b/public/search.php index ea75fc2..e3e7539 100644 --- a/public/search.php +++ b/public/search.php @@ -26,7 +26,7 @@ switch ($t) { case 'image': - $totalPages = $db->getTotalImages(); + $totalPages = $sphinx->getHostImagesTotal(); $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s image or enter the new one...'), $totalPages), sprintf(_('Over %s images or enter the new one...'), $totalPages), @@ -36,7 +36,7 @@ switch ($t) { break; default: - $totalPages = $db->getTotalPages(); + $totalPages = $sphinx->getHostPagesTotal(); $placeholder = Filter::plural($totalPages, [sprintf(_('Over %s page or enter the new one...'), $totalPages), sprintf(_('Over %s pages or enter the new one...'), $totalPages),