From 1a94f5b831abe1ed83ce6ef11ef67bd44fdef819 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Mon, 11 Dec 2023 19:54:18 -0500 Subject: [PATCH] Fixing Issue #5612 - Function db_check_reconnect() issues Function db_check_reconnect() does not properly return a value --- CHANGELOG | 1 + lib/database.php | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index b2ecc76b76..26670b3b3e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -34,6 +34,7 @@ Cacti CHANGELOG -issue#5590: Secondary LDAP server not evaluated when the first one has failed -issue#5602: Missing "break" for case statement in cli/add_device.php -issue#5609: XML Bug when parsing Data Query XML Resource File when no field direction attribute is specified +-issue#5612: Function db_check_reconnect() does not properly return a value -feature#5577: Provide new templates for ArubaOS switch, Aruba wifi controller and HPE iLO to be available during install -feature#5597: Provide new templates for Arubai OSCX 6x00 switch to be available during install diff --git a/lib/database.php b/lib/database.php index ed1473002d..fcbf4cd4ee 100644 --- a/lib/database.php +++ b/lib/database.php @@ -227,6 +227,15 @@ function db_connect_real($device, $user, $pass, $db_name, $db_type = 'mysql', $p return false; } +/** + * db_check_reconnect - Check the database connection. If the connection is gone + * attempt to reconnect, otherwise return the connection + * + * @param bool|object The connection to check + * @param bool Wether or not to log the connection check + * + * @return bool The database true is the database is connected else false + */ function db_check_reconnect($db_conn = false, $log = true) { global $config, $database_details; @@ -279,7 +288,7 @@ function db_check_reconnect($db_conn = false, $log = true) { db_close(); // Connect to the database server - db_connect_real( + $cnn_id = db_connect_real( $database_hostname, $database_username, $database_password, @@ -292,6 +301,14 @@ function db_check_reconnect($db_conn = false, $log = true) { $database_ssl_cert, $database_ssl_ca ); + + if ($cnn_id !== false) { + return true; + } else { + return false; + } + } else { + return true; } }