Skip to content

Commit

Permalink
Fixing Issue #5612 - Function db_check_reconnect() issues
Browse files Browse the repository at this point in the history
Function db_check_reconnect() does not properly return a value
  • Loading branch information
TheWitness committed Dec 12, 2023
1 parent 9460e1d commit 1a94f5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 18 additions & 1 deletion lib/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
}

Expand Down

0 comments on commit 1a94f5b

Please sign in to comment.