diff --git a/pandora_console/general/footer.php b/pandora_console/general/footer.php
index 2383e4b468..23022c3d75 100644
--- a/pandora_console/general/footer.php
+++ b/pandora_console/general/footer.php
@@ -32,7 +32,9 @@ echo '
';
echo '';
if (isset ($config['debug'])) {
- echo ' - Saved '.format_numeric ($sql_cache["saved"]).' Queries';
+ $cache_info = array();
+ $cache_info = db_get_cached_queries();
+ echo ' - Saved '.$cache_info[0].' Queries';
}
?>
diff --git a/pandora_console/include/db/mysql.php b/pandora_console/include/db/mysql.php
index 00a49395db..3f4a924f67 100644
--- a/pandora_console/include/db/mysql.php
+++ b/pandora_console/include/db/mysql.php
@@ -35,6 +35,8 @@ function mysql_connect_db($host = null, $db = null, $user = null, $pass = null,
return false;
}
+ db_change_cache_id ($db, $host);
+
mysql_select_db($db, $connect_id);
return $connect_id;
}
@@ -287,9 +289,9 @@ function mysql_db_process_sql($sql, $rettype = "affected_rows", $dbconnection =
if ($sql == '')
return false;
- if ($cache && ! empty ($sql_cache[$sql])) {
- $retval = $sql_cache[$sql];
- $sql_cache['saved']++;
+ if ($cache && ! empty ($sql_cache[$sql_cache['id']][$sql])) {
+ $retval = $sql_cache[$sql_cache['id']][$sql];
+ $sql_cache['saved'][$sql_cache['id']]++;
db_add_database_debug_trace ($sql);
}
else {
@@ -335,7 +337,7 @@ function mysql_db_process_sql($sql, $rettype = "affected_rows", $dbconnection =
}
if ($cache === true)
- $sql_cache[$sql] = $retval;
+ $sql_cache[$sql_cache ['id']][$sql] = $retval;
mysql_free_result ($result);
}
}
diff --git a/pandora_console/include/db/oracle.php b/pandora_console/include/db/oracle.php
index d1079cb3d0..89f0d0f73c 100644
--- a/pandora_console/include/db/oracle.php
+++ b/pandora_console/include/db/oracle.php
@@ -45,6 +45,8 @@ function oracle_connect_db($host = null, $db = null, $user = null, $pass = null,
$date_format = oci_parse($connect_id , 'alter session set NLS_DATE_FORMAT =\'YYYY-MM-DD HH24:MI:SS\'');
$decimal_separator = oci_parse($connect_id , 'alter session set NLS_NUMERIC_CHARACTERS =\'.,\'');
+ db_change_cache_id($host, $db);
+
oci_execute($datetime_tz_format);
oci_execute($datetime_format);
oci_execute($date_format);
@@ -224,9 +226,9 @@ function oracle_db_process_sql($sql, $rettype = "affected_rows", $dbconnection =
if ($sql == '')
return false;
- if ($cache && ! empty ($sql_cache[$sql])) {
- $retval = $sql_cache[$sql];
- $sql_cache['saved']++;
+ if ($cache && ! empty ($sql_cache[$sql_cache['id']][$sql])) {
+ $retval = $sql_cache[$sql_cache['id']][$sql];
+ $sql_cache['saved'][$sql_cache['id']]++;
db_add_database_debug_trace ($sql);
}
else {
diff --git a/pandora_console/include/db/postgresql.php b/pandora_console/include/db/postgresql.php
index b466b658a3..0bc8d20774 100644
--- a/pandora_console/include/db/postgresql.php
+++ b/pandora_console/include/db/postgresql.php
@@ -37,6 +37,8 @@ function postgresql_connect_db($host = null, $db = null, $user = null, $pass = n
if (! $connect_id) {
return false;
}
+
+ db_change_cache_id($host, $db);
return $connect_id;
}
@@ -200,9 +202,9 @@ function postgresql_db_process_sql($sql, $rettype = "affected_rows", $dbconnecti
if ($sql == '')
return false;
- if ($cache && ! empty ($sql_cache[$sql])) {
- $retval = $sql_cache[$sql];
- $sql_cache['saved']++;
+ if ($cache && ! empty ($sql_cache[$sql_cache['id']][$sql])) {
+ $retval = $sql_cache[$sql_cache['id']][$sql];
+ $sql_cache['saved'][$sql_cache['id']]++;
db_add_database_debug_trace ($sql);
}
else {
diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php
index 58671db15c..d8b469cdc9 100644
--- a/pandora_console/include/functions_db.php
+++ b/pandora_console/include/functions_db.php
@@ -223,7 +223,7 @@ function db_logoff ($id_user, $ip) {
db_pandora_audit("Logoff", "Logged out", $id_user, $ip);
}
-$sql_cache = array ('saved' => 0);
+$sql_cache = array ('saved' => array());
/**
* Get the first value of the first row of a table in the database.
@@ -613,7 +613,40 @@ function db_add_database_debug_trace ($sql, $result = false, $affected = false,
function db_clean_cache() {
global $sql_cache;
- $sql_cache = array ('saved' => 0);
+ $sql_cache = array ('saved' => array ());
+}
+
+/**
+ * Change the sql cache id to another value
+ *
+ * @return None
+ */
+function db_change_cache_id($name, $host) {
+ global $sql_cache;
+
+ // Update the sql cache identification
+ $sql_cache['id'] = $name . "_" . $host;
+ if (!isset ($sql_cache['saved'][$sql_cache['id']])){
+ $sql_cache['saved'][$sql_cache['id']] = 0;
+ }
+}
+
+/**
+ * Get the total cached queries and the databases checked
+ *
+ * @return (total_queries, total_dbs)
+ */
+function db_get_cached_queries() {
+ global $sql_cache;
+
+ $total_saved = 0;
+ $total_dbs = 0;
+ foreach ($sql_cache['saved'] as $saver) {
+ $total_saved += format_numeric($saver);
+ $total_dbs++;
+ }
+
+ return array ($total_saved, $total_dbs);
}
/**
diff --git a/pandora_console/operation/agentes/exportdata.csv.php b/pandora_console/operation/agentes/exportdata.csv.php
index 2987a58cab..99b44f7f86 100644
--- a/pandora_console/operation/agentes/exportdata.csv.php
+++ b/pandora_console/operation/agentes/exportdata.csv.php
@@ -54,7 +54,7 @@ if (!empty ($module)) {
// Disable SQL cache
global $sql_cache;
- $sql_cache = array ('saved' => 0);
+ $sql_cache = array ('saved' => array());
//Convert start time and end time to unix timestamps
diff --git a/pandora_console/operation/agentes/exportdata.excel.php b/pandora_console/operation/agentes/exportdata.excel.php
index 82bc16aaf2..7957dae886 100644
--- a/pandora_console/operation/agentes/exportdata.excel.php
+++ b/pandora_console/operation/agentes/exportdata.excel.php
@@ -53,7 +53,7 @@ if (!empty ($module)) {
// Disable SQL cache
global $sql_cache;
- $sql_cache = array ('saved' => 0);
+ $sql_cache = array ('saved' => array());
//Convert start time and end time to unix timestamps
diff --git a/pandora_console/operation/agentes/exportdata.php b/pandora_console/operation/agentes/exportdata.php
index 7c16ac5623..ea5a3caf3c 100644
--- a/pandora_console/operation/agentes/exportdata.php
+++ b/pandora_console/operation/agentes/exportdata.php
@@ -68,7 +68,7 @@ if (!empty ($export_btn) && !empty ($module)) {
// Disable SQL cache
global $sql_cache;
- $sql_cache = array ('saved' => 0);
+ $sql_cache = array ('saved' => array());
//Convert start time and end time to unix timestamps