From 4cdc4598c7297018ff13f2d1500b904bfd4fc72d Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Thu, 16 Jul 2009 14:20:05 +0000 Subject: [PATCH] FOUND_ROWS works with last SELECT git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@844 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- adminer/select.inc.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 9929edfb..ac5ba0e1 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -270,6 +270,11 @@ if (!$columns) { $rows[] = $row; } $result->free(); + // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest) + $found_rows = (intval($limit) && count($group) < count($select) + ? $dbh->result($dbh->query(" SELECT FOUND_ROWS()")) // space to allow mysql.trace_mode + : count($rows) + ); $foreign_keys = array(); foreach (foreign_keys($_GET["select"]) as $foreign_key) { @@ -357,12 +362,13 @@ if (!$columns) { } echo "\n"; + if (intval($limit) && count($group) >= count($select)) { + // slow with big tables + ob_flush(); + flush(); + $found_rows = $dbh->result($dbh->query("SELECT COUNT(*) FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : ""))); + } echo "

"; - // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest) - $found_rows = (intval($limit) ? $dbh->result($dbh->query(count($group) < count($select) - ? " SELECT FOUND_ROWS()" // space to allow mysql.trace_mode - : "SELECT COUNT(*) FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") - )) : count($rows)); if (intval($limit) && $found_rows > $limit) { // display first, previous 3, next 3 and last page $max_page = floor(($found_rows - 1) / $limit);