From fceac1e8735d80f6d4096889961e4684f0395081 Mon Sep 17 00:00:00 2001 From: Ivan Tcholakov Date: Thu, 18 Mar 2010 07:24:08 +0200 Subject: [PATCH] Database::num_rows() method - Adding a validation check for the input parameter. Some corrections in the comments. --- main/inc/lib/database.lib.php | 82 +++++++++++++++-------------------- 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index 096417e0d0..4a572393cc 100755 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -1,10 +1,10 @@ **/ public static function num_rows($result) { - return mysql_num_rows($result); + return is_resource($result) ? mysql_num_rows($result) : false; } /** @@ -907,11 +899,11 @@ class Database { * @result mixed One cell of the result, or FALSE on error */ public static function result($resource, $row, $field = '') { - return mysql_num_rows($resource) > 0 ? (!empty($field) ? mysql_result($resource, $row, $field) : mysql_result($resource, $row)) : null; + return self::num_rows($resource) > 0 ? (!empty($field) ? mysql_result($resource, $row, $field) : mysql_result($resource, $row)) : null; } /** - * This function returns a resource + * This method returns a resource * Documentation has been added by Arthur Portugal * Some adaptations have been implemented by Ivan Tcholakov, 2009, 2010 * @author Olivier Brouckaert @@ -1021,9 +1013,7 @@ class Database { } /* - ----------------------------------------------------------------------------- Encodings and collations supported by MySQL database server - ----------------------------------------------------------------------------- */ /** @@ -1152,11 +1142,9 @@ class Database { } /* - ----------------------------------------------------------------------------- Private methods You should not access these from outside the class No effort is made to keep the names / results the same. - ----------------------------------------------------------------------------- */ /** @@ -1223,7 +1211,7 @@ class Database { } /** - * This private function encapsulates a table with relations between + * This private method encapsulates a table with relations between * conventional and MuSQL-specific encoding identificators. * @author Ivan Tcholakov */ @@ -1299,9 +1287,7 @@ class Database { } /* - ============================================================================== DEPRECATED METHODS - ============================================================================== */ /**