From 954b18c169cbec218cab5fe4785471655206833e Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sun, 13 May 2012 21:09:03 +0000 Subject: [PATCH] functions.inc.php - create_page_browser(): revert r1387 and... - db_query(): ...replace it with the correct fix ;-) (avoid mysqli reconnects) The problem was that db_query() used is_resource() to check if we already have a database connection, but a mysqli connection is an object, not a resource. This resulted in a new database connection for each query. Therefore mysqli "forgot" the value of SET @row before executing the following SELECT query (which used a new mysqli connection). The fix is to also check with is_object() to avoid mysqli reconnects. git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1388 a1433add-5e2c-0410-b055-b7f2511e0802 --- functions.inc.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/functions.inc.php b/functions.inc.php index 0f94075b..1bf73957 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -500,10 +500,11 @@ function create_page_browser($idxfield, $querypart) { # get labels for relevant rows (first and last of each page) $page_size_zerobase = $page_size - 1; $query = " - SELECT *, MOD(idx.row, $page_size) FROM ( + SELECT * FROM ( SELECT $idxfield AS label, @row := @row + 1 AS row $querypart ) idx WHERE MOD(idx.row, $page_size) IN (0,$page_size_zerobase) OR idx.row = $count_results "; + if ('pgsql'==$CONF['database_type']) { $query = " SELECT * FROM ( @@ -1517,7 +1518,8 @@ function db_query ($query, $ignore_errors = 0) { $error_text = ""; if ($ignore_errors) $DEBUG_TEXT = ""; - if (!is_resource($link)) $link = db_connect (); + # mysql and pgsql $link are resources, mysqli $link is an object + if (! (is_resource($link) || is_object($link) ) ) $link = db_connect (); if ($CONF['database_type'] == "mysql") $result = @mysql_query ($query, $link) or $error_text = "

DEBUG INFORMATION:
Invalid query ($query) : " . mysql_error($link) . "$DEBUG_TEXT";