diff --git a/include/database/PearDatabase.php b/include/database/PearDatabase.php
index 254fe9abc2974f6cef876173743c847296b63beb..f81d7911e4b5d5bfb7b66e508f7a4f9eae1717eb 100644
--- a/include/database/PearDatabase.php
+++ b/include/database/PearDatabase.php
@@ -357,8 +357,20 @@ class PearDatabase{
 		$this->executeSetNamesUTF8SQL();
 
 		$sql_start_time = microtime(true);
-		$params = $this->flatten_array($params);
-		if (is_array($params) && count($params) > 0) {
+
+		// flatten only when params has array inside.
+		$flatten_params = false;
+		foreach ($params as $val) {
+			if (is_array($val)) {
+				$flatten_params = true;
+				break;
+			}
+		}
+		if ($flatten_params) {
+			$params = $this->flatten_array($params);
+		}
+
+		if ($log->isDebugEnabled() && is_array($params) && count($params) > 0) {
 			$log->debug('Prepared sql query parameters : [' . implode(",", $params) . ']');
 		}
 
diff --git a/modules/Vtiger/helpers/Logger.php b/modules/Vtiger/helpers/Logger.php
index f9a61ef77bbd1fcc9f1efb6f511392474c7a60d7..0198dc142fc2931643fc30b36e27b644a37cff70 100644
--- a/modules/Vtiger/helpers/Logger.php
+++ b/modules/Vtiger/helpers/Logger.php
@@ -76,6 +76,10 @@ class Logger {
     public function warn($message) {}
     public function error($message) {}
 
+    public function isDebugEnabled() {
+        return self::$logLevel == 100;
+    }
+
 }
 
 // Define extended version of Monolog Logger to support functions
@@ -83,6 +87,16 @@ class MonologLoggerEx extends MonologLogger {
     function fatal($message, $context = array()) {
         $this->error($message, $context);
     }
+    function isDebugEnabled() {
+        $debugLevel = false;
+        foreach ($this->getHandlers() as $handler) {
+            if ($handler->getLogLevel() == static::DEBUG) {
+                $debugLevel = true;
+                break;
+            }
+        }
+        return $debugLevel;
+    }
 }
 
 // Define a custom log formatter