From 334ed431b28c202a1e096e0d7cbb303b45675701 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Wed, 2 Feb 2005 16:21:54 +0000 Subject: [PATCH] bug 1108521 part 3: do not send a boolean to mysql_num_rows or mysqli_num_rows --- ChangeLog | 4 ++++ libraries/dbi/mysql.dbi.lib.php | 6 +++++- libraries/dbi/mysqli.dbi.lib.php | 12 +++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8dbf59e6..ebaa4f4cf 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ phpMyAdmin - Changelog $Id$ $Source$ +2005-02-02 Marc Delisle + * libraries/dbi/*: PMA_DBI_num_rows(): do not send a boolean + to mysqli_num_rows() or mysql_num_row(), it expects a result resource + 2005-01-30 Marc Delisle * libraries/export/sql.php: bug #1108521, part 2: mysqli_num_rows cannot be used with MYSQL_USE_RESULT diff --git a/libraries/dbi/mysql.dbi.lib.php b/libraries/dbi/mysql.dbi.lib.php index 6bffb7fac..e1eb7ea91 100644 --- a/libraries/dbi/mysql.dbi.lib.php +++ b/libraries/dbi/mysql.dbi.lib.php @@ -214,7 +214,11 @@ function PMA_DBI_close($link = NULL) { } function PMA_DBI_num_rows($result) { - return mysql_num_rows($result); + if (!is_bool($result)) { + return mysql_num_rows($result); + } else { + return 0; + } } function PMA_DBI_insert_id($link = NULL) { diff --git a/libraries/dbi/mysqli.dbi.lib.php b/libraries/dbi/mysqli.dbi.lib.php index 6595517e9..1538c3b29 100644 --- a/libraries/dbi/mysqli.dbi.lib.php +++ b/libraries/dbi/mysqli.dbi.lib.php @@ -113,6 +113,11 @@ function PMA_DBI_try_query($query, $link = NULL, $options = 0) { $query = PMA_convert_charset($query); } return mysqli_query($link, $query, $method); + // From the PHP manual: + // "note: returns TRUE on success or FALSE on failure. For SELECT, + // SHOW, DESCRIBE or EXPLAIN, mysqli_query() will return a result object" + // so, do not use the return value to feed mysqli_num_rows() if it's + // a boolean } // The following function is meant for internal use only. @@ -224,7 +229,12 @@ function PMA_DBI_close($link = NULL) { } function PMA_DBI_num_rows($result) { - return @mysqli_num_rows($result); + // see the note for PMA_DBI_try_query(); + if (!is_bool($result)) { + return @mysqli_num_rows($result); + } else { + return 0; + } } function PMA_DBI_insert_id($link = '') {