From 2e4ade9621ea8cbd61a3c0226da628fdedf1754a Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 19 Mar 2015 20:41:38 -0700 Subject: [PATCH] CRM-16132 - Fix warning, "mysqli_error() expects parameter 1 to be mysqli" The error-reporting code tests whehter it should lookup errors using mysql_error() or mysqli_error(). However, it incorrectly assumes that function-existence implies active-link. But both functions may exist -- even though only one connection is active. The active, in-use connection is determined by the DSN. --- CRM/Core/Error.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/CRM/Core/Error.php b/CRM/Core/Error.php index 8fce918295..cb4c217a3a 100644 --- a/CRM/Core/Error.php +++ b/CRM/Core/Error.php @@ -192,7 +192,16 @@ class CRM_Core_Error extends PEAR_ErrorStack { $error['type'] = $pearError->getType(); $error['user_info'] = $pearError->getUserInfo(); $error['to_string'] = $pearError->toString(); - if (function_exists('mysql_error') && + + // We access connection info via _DB_DATAOBJECT instead + // of, e.g., calling getDatabaseConnection(), so that we + // can avoid infinite loops. + global $_DB_DATAOBJECT; + + if (!isset($_DB_DATAOBJECT['CONFIG']['database'])) { + // we haven't setup sql, so it's not our sql error... + } + elseif (preg_match('/^mysql:/', $_DB_DATAOBJECT['CONFIG']['database']) && mysql_error() ) { $mysql_error = mysql_error() . ', ' . mysql_errno(); @@ -201,13 +210,9 @@ class CRM_Core_Error extends PEAR_ErrorStack { // execute a dummy query to clear error stack mysql_query('select 1'); } - elseif (function_exists('mysqli_error')) { + elseif (preg_match('/^mysqli:/', $_DB_DATAOBJECT['CONFIG']['database'])) { $dao = new CRM_Core_DAO(); - // we do it this way, since calling the function - // getDatabaseConnection could potentially result - // in an infinite loop - global $_DB_DATAOBJECT; if (isset($_DB_DATAOBJECT['CONNECTIONS'][$dao->_database_dsn_md5])) { $conn = $_DB_DATAOBJECT['CONNECTIONS'][$dao->_database_dsn_md5]; $link = $conn->connection; -- 2.25.1