From 1452bde1acd6c0aeee2c04b9fdd82e10800e700d Mon Sep 17 00:00:00 2001 From: markjcrane Date: Sat, 17 Jun 2023 22:29:15 -0600 Subject: [PATCH] Update the database class to find the require.php --- resources/classes/database.php | 41 +++++++++++++++++++++------------- resources/require.php | 2 +- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/resources/classes/database.php b/resources/classes/database.php index 11f3d32526..c9f3b28df9 100644 --- a/resources/classes/database.php +++ b/resources/classes/database.php @@ -392,22 +392,15 @@ public function connect() { //includes files - //require dirname(__DIR__, 2) . "/resources/require.php"; - - //set the include path - $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE); - set_include_path(parse_ini_file($conf[0])['document.root']); - - //parset the config.conf file - $conf = parse_ini_file($conf[0]); + require dirname(__DIR__, 2) . "/resources/require.php"; //get the database connection settings - $db_type = $conf['database.0.type']; - $db_host = $conf['database.0.host']; - $db_port = $conf['database.0.port']; - $db_name = $conf['database.0.name']; - $db_username = $conf['database.0.username']; - $db_password = $conf['database.0.password']; + //$db_type = $conf['database.0.type']; + //$db_host = $conf['database.0.host']; + //$db_port = $conf['database.0.port']; + //$db_name = $conf['database.0.name']; + //$db_username = $conf['database.0.username']; + //$db_password = $conf['database.0.password']; //debug info //echo "db type:".$db_type."\n"; @@ -645,6 +638,13 @@ $this->connect(); } + //if unable to connect to the database + if (!$this->db) { + echo "Connection Failed
\n"; + echo "line number ".__line__."
\n"; + exit; + } + //query table store to see if the table exists $sql = ""; if ($this->type == "sqlite") { @@ -1477,11 +1477,20 @@ $this->connect(); } + //unable to connect to the database + if (!$this->db) { + echo "Connection Failed
\n"; + echo "line number ".__line__."
\n"; + exit; + } + //set the error mode - $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + if ($this->db) { + $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } //reduce prepared statement latency - if (defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')) { + if ($this->db && defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')) { $this->db->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true); } diff --git a/resources/require.php b/resources/require.php index a3d5cb617c..c8581ecab8 100644 --- a/resources/require.php +++ b/resources/require.php @@ -102,7 +102,7 @@ require_once "resources/php.php"; require_once "resources/functions.php"; if (is_array($conf) && count($conf) > 0) { - require "resources/pdo.php"; + require_once "resources/pdo.php"; require_once "resources/cidr.php"; if (file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/resources/switch.php")) { require_once "resources/switch.php";