From da1727c64fc7f8538b9e97c6f28bc0ff8dd1d556 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 17 Aug 2024 12:17:25 -0700 Subject: [PATCH] BoincDb::get(): if open to different dbnum, close and reconnect. Don't throw exception if connect fails --- html/inc/boinc_db.inc | 5 ++++- html/inc/db_conn.inc | 12 ++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/html/inc/boinc_db.inc b/html/inc/boinc_db.inc index 7b169be320..ff3b4c20d4 100644 --- a/html/inc/boinc_db.inc +++ b/html/inc/boinc_db.inc @@ -105,7 +105,10 @@ class BoincDb { static function get($dbnum = 0) { global $generating_xml; if (isset(self::$instance)) { - return self::$instance; + if (self::$dbnum == $dbnum) { + return self::$instance; + } + close(); } if (web_stopped()) { if ($generating_xml) { diff --git a/html/inc/db_conn.inc b/html/inc/db_conn.inc index 910d2f9af9..b39ae8d36f 100644 --- a/html/inc/db_conn.inc +++ b/html/inc/db_conn.inc @@ -33,14 +33,10 @@ class DbConn { } else { $port = null; } - if (1) { // don't use persistent connections for now - $this->db_conn = @new mysqli( - $host, $user, $passwd, $name, $port - ); - } else { - $this->db_conn = @new mysqli( - 'p:'.$host, $user, $passwd, $name, $port - ); + try { + $this->db_conn = @new mysqli($host, $user, $passwd, $name, $port); + } catch(Exception $e) { + return false; } if (mysqli_connect_error()) { return false;