From: Roland Haeder Date: Mon, 6 Jun 2016 20:05:26 +0000 (+0200) Subject: introduced isSqlResult() which encapsulates checking MySQL/i results X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=commitdiff_plain;h=095f5ab59b539834d2c67e5d409d01820e10d8be introduced isSqlResult() which encapsulates checking MySQL/i results Signed-off-by: Roland Häder --- diff --git a/inc/db/lib-mysql.php b/inc/db/lib-mysql.php index 1cb749c44c..56cfe52861 100644 --- a/inc/db/lib-mysql.php +++ b/inc/db/lib-mysql.php @@ -360,5 +360,11 @@ function isValidSqlLink ($linkResource) { return is_resource($linkResource); } +// Checks whether given result is a valid SQL result +function isSqlResult ($result) { + // TODO: Can't this be made better? + return is_resource($result); +} + // [EOF] ?> diff --git a/inc/db/lib-mysqli.php b/inc/db/lib-mysqli.php index bfce1564a0..b3559bf7e8 100644 --- a/inc/db/lib-mysqli.php +++ b/inc/db/lib-mysqli.php @@ -346,7 +346,7 @@ function setSqlError ($file, $line, $message) { // Checks whether given link is a valid SQL link function isValidSqlLink ($linkInstance) { - // Is it a resource? + // Is it an object? $isValid = (($linkInstance instanceof mysqli) || ($linkInstance instanceof mysqli_result)); // Debug message @@ -356,5 +356,17 @@ function isValidSqlLink ($linkInstance) { return $isValid; } +// Checks whether given result is really a result +function isSqlResult ($resultInstance) { + // Is it a resource? + $isValid = ($resultInstance instanceof mysqli_result); + + // Debug message + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'resultInstance[]=' . gettype($resultInstance). ',isValid=' . intval($isValid)); + + // Return result + return $isValid; +} + // [EOF] ?> diff --git a/inc/module-functions.php b/inc/module-functions.php index f5782820c8..41c45b648c 100644 --- a/inc/module-functions.php +++ b/inc/module-functions.php @@ -80,7 +80,7 @@ function getModuleTitle ($module) { } else { // No name found $data['title'] = '{%message,UNKNOWN_MODULE_DETECTED_TITLE=' . $module . '%}'; - if ((is_resource($result)) && (ifSqlHasZeroNumRows($result))) { + if ((isSqlResult($result)) && (ifSqlHasZeroNumRows($result))) { // Add module to database and ignore return value checkModulePermissions($module); } // END - if diff --git a/inc/modules/admin/what-list_notifications.php b/inc/modules/admin/what-list_notifications.php index 05fad58a3e..eb8b135e48 100644 --- a/inc/modules/admin/what-list_notifications.php +++ b/inc/modules/admin/what-list_notifications.php @@ -74,7 +74,9 @@ ORDER BY $add = ' LIMIT ' . (bigintval(getRequestElement('offset')) * bigintval(getRequestElement('page')) - bigintval(getRequestElement('offset'))) . ', ' . bigintval(getRequestElement('offset')); // Add limitation -if (!empty($SQL2)) $SQL2 .= $add; +if (!empty($SQL2)) { + $SQL2 .= $add; +} // END - if if ((isExtensionActive('bonus')) && (!ifSqlHasZeroNumRows($result_max)) && (!empty($SQL2))) { // Run SQL query for notification mails @@ -107,7 +109,7 @@ if ((isExtensionActive('bonus')) && (!ifSqlHasZeroNumRows($result_max)) && (!emp // Load main template loadTemplate('admin_list_notify_emails', FALSE, $content); } -} elseif ((sqlNumRows($result_max) === 0) && (is_resource($result_max))) { +} elseif ((sqlNumRows($result_max) === 0) && (isSqlResult($result_max))) { // No notifications found displayMessage('{--ADMIN_NO_NOTIFICATIONS--}'); }