diff --git a/auth/admin/classes/common/DBService.php b/auth/admin/classes/common/DBService.php index 1cf8f559c..52b5734b1 100644 --- a/auth/admin/classes/common/DBService.php +++ b/auth/admin/classes/common/DBService.php @@ -22,6 +22,20 @@ class DBService extends Object { protected $db; protected $config; protected $error; + private static $_instance; //The single instance + + +/* + Get an instance of the Database + @return Instance + */ + public static function getInstance() { + if(!self::$_instance) { // If no instance then make one + self::$_instance = new self(); + } + return self::$_instance; + } + protected function init(NamedArguments $arguments) { parent::init($arguments); diff --git a/auth/admin/classes/common/DatabaseObject.php b/auth/admin/classes/common/DatabaseObject.php index 4b3358697..2ad2d6b23 100644 --- a/auth/admin/classes/common/DatabaseObject.php +++ b/auth/admin/classes/common/DatabaseObject.php @@ -52,7 +52,7 @@ protected function init(NamedArguments $arguments) { $this->primaryKeyName = $arguments->primaryKeyName; $this->primaryKey = $arguments->primaryKey; - $this->db = new DBService; + $this->db = DBService::getInstance(); $this->defineRelationships(); //$this->defineAttributes(); $this->overridePrimaryKeyName(); diff --git a/licensing/admin/classes/common/DBService.php b/licensing/admin/classes/common/DBService.php index 5b6c9f0fb..30a858196 100644 --- a/licensing/admin/classes/common/DBService.php +++ b/licensing/admin/classes/common/DBService.php @@ -23,6 +23,20 @@ class DBService extends Object { protected $db; protected $config; protected $error; + private static $_instance; //The single instance + + +/* + Get an instance of the Database + @return Instance + */ + public static function getInstance() { + if(!self::$_instance) { // If no instance then make one + self::$_instance = new self(); + } + return self::$_instance; + } + protected function init(NamedArguments $arguments) { parent::init($arguments); diff --git a/licensing/admin/classes/common/DatabaseObject.php b/licensing/admin/classes/common/DatabaseObject.php index 7c27624fb..55d17ba60 100644 --- a/licensing/admin/classes/common/DatabaseObject.php +++ b/licensing/admin/classes/common/DatabaseObject.php @@ -52,7 +52,7 @@ protected function init(NamedArguments $arguments) { $this->primaryKeyName = $arguments->primaryKeyName; $this->primaryKey = $arguments->primaryKey; - $this->db = new DBService; + $this->db = DBService::getInstance(); $this->defineRelationships(); //$this->defineAttributes(); $this->overridePrimaryKeyName(); diff --git a/licensing/admin/classes/common/Utility.php b/licensing/admin/classes/common/Utility.php index 9c7de21ab..cc8787edc 100644 --- a/licensing/admin/classes/common/Utility.php +++ b/licensing/admin/classes/common/Utility.php @@ -98,7 +98,7 @@ public function fixLicenseFormEnter($editLicenseID){ if ($editLicenseID == ""){ //need to get the most recent added license since it will have been added but we didn''t get the resonse of the new license ID //since this will have happened instantly we can be safe to assume this is the correct record - $this->db = new DBService; + $this->db = DBService::getInstance(); $result = $this->db->processQuery("select max(licenseID) max_licenseID from License;", 'assoc'); diff --git a/management/admin/classes/common/DBService.php b/management/admin/classes/common/DBService.php index 71effe4dc..61b068f93 100644 --- a/management/admin/classes/common/DBService.php +++ b/management/admin/classes/common/DBService.php @@ -23,6 +23,21 @@ class DBService extends Object { protected $db; protected $config; protected $error; + private static $_instance; //The single instance + + +/* + Get an instance of the Database + @return Instance + */ + public static function getInstance() { + if(!self::$_instance) { // If no instance then make one + self::$_instance = new self(); + } + return self::$_instance; + } + + protected function init(NamedArguments $arguments) { parent::init($arguments); diff --git a/management/admin/classes/common/DatabaseObject.php b/management/admin/classes/common/DatabaseObject.php index 320eab78d..e3f7a7c9b 100644 --- a/management/admin/classes/common/DatabaseObject.php +++ b/management/admin/classes/common/DatabaseObject.php @@ -52,7 +52,7 @@ protected function init(NamedArguments $arguments) { $this->primaryKeyName = $arguments->primaryKeyName; $this->primaryKey = $arguments->primaryKey; - $this->db = new DBService; + $this->db = DBService::getInstance(); $this->defineRelationships(); //$this->defineAttributes(); $this->overridePrimaryKeyName(); diff --git a/management/admin/classes/common/Utility.php b/management/admin/classes/common/Utility.php index 1c447549c..25bf0266b 100644 --- a/management/admin/classes/common/Utility.php +++ b/management/admin/classes/common/Utility.php @@ -94,7 +94,7 @@ public function fixLicenseFormEnter($editLicenseID){ if ($editLicenseID == ""){ //need to get the most recent added license since it will have been added but we didn''t get the resonse of the new license ID //since this will have happened instantly we can be safe to assume this is the correct record - $this->db = new DBService; + $this->db = DBService::getInstance(); $result = $this->db->processQuery("select max(licenseID) max_licenseID from License;", 'assoc'); diff --git a/organizations/admin/classes/common/DBService.php b/organizations/admin/classes/common/DBService.php index e6753802a..bed2a25ef 100644 --- a/organizations/admin/classes/common/DBService.php +++ b/organizations/admin/classes/common/DBService.php @@ -22,6 +22,21 @@ class DBService extends Object { protected $db; protected $config; protected $error; + private static $_instance; //The single instance + + +/* + Get an instance of the Database + @return Instance + */ + public static function getInstance() { + if(!self::$_instance) { // If no instance then make one + self::$_instance = new self(); + } + return self::$_instance; + } + + protected function init(NamedArguments $arguments) { parent::init($arguments); diff --git a/organizations/admin/classes/common/DatabaseObject.php b/organizations/admin/classes/common/DatabaseObject.php index 445a163ef..69568a17a 100644 --- a/organizations/admin/classes/common/DatabaseObject.php +++ b/organizations/admin/classes/common/DatabaseObject.php @@ -45,7 +45,7 @@ protected function init(NamedArguments $arguments) { $this->primaryKeyName = $arguments->primaryKeyName; $this->primaryKey = $arguments->primaryKey; - $this->db = new DBService; + $this->db = DBService::getInstance(); $arguments->setDefaultValueForArgumentName('dbName',$this->db->config->database->name); $this->dbName = $arguments->dbName; diff --git a/reports/admin/classes/common/DBService.php b/reports/admin/classes/common/DBService.php index 5c7665955..b910673b7 100644 --- a/reports/admin/classes/common/DBService.php +++ b/reports/admin/classes/common/DBService.php @@ -18,6 +18,21 @@ class DBService { protected static $db = null; protected $error; + private static $_instance; //The single instance + + +/* + Get an instance of the Database + @return Instance + */ + public static function getInstance() { + if(!self::$_instance) { // If no instance then make one + self::$_instance = new self(); + } + return self::$_instance; + } + + public function __construct($dbname = null){ Config::init(); if (!self::$db && !(self::$db = new mysqli(Config::$database->host, Config::$database->username, Config::$database->password))){ diff --git a/reports/admin/classes/domain/ParameterFactory.php b/reports/admin/classes/domain/ParameterFactory.php index 4338d90bc..d5c5bd02e 100644 --- a/reports/admin/classes/domain/ParameterFactory.php +++ b/reports/admin/classes/domain/ParameterFactory.php @@ -14,7 +14,7 @@ class ParameterFactory { public static function makeParam($reportID,$reportParameterID) { $parm = null; - $db = new DBService(); + $db = DBService::getInstance(); $result = $db ->query("SELECT rp.*, rpm.parentReportParameterID FROM ReportParameter rp, ReportParameterMap rpm diff --git a/reports/admin/classes/report/Report.php b/reports/admin/classes/report/Report.php index 2a5c1c942..89b0abd7b 100644 --- a/reports/admin/classes/report/Report.php +++ b/reports/admin/classes/report/Report.php @@ -36,7 +36,7 @@ public function applyDateRange(array $dateRange) { } public function __construct($id){ - $this->db = new DBService(); + $this->db = DBService::getInstance(); $result = $this->db ->query("SELECT reportName, reportDatabaseName FROM Report WHERE reportID = '$id' LIMIT 1") ->fetchRow(MYSQLI_ASSOC); diff --git a/reports/index.php b/reports/index.php index dba4ca9cd..2c604c36e 100644 --- a/reports/index.php +++ b/reports/index.php @@ -101,7 +101,7 @@ query("SELECT reportID, reportName FROM Report ORDER BY 2, 1")->fetchRows(MYSQLI_ASSOC) as $report ){ echo "