1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* /classes/DomainMOD/Database.php |
4
|
|
|
* |
5
|
|
|
* This file is part of DomainMOD, an open source domain and internet asset manager. |
6
|
|
|
* Copyright (c) 2010-2017 Greg Chetcuti <[email protected]> |
7
|
|
|
* |
8
|
|
|
* Project: http://domainmod.org Author: http://chetcuti.com |
9
|
|
|
* |
10
|
|
|
* DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public |
11
|
|
|
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later |
12
|
|
|
* version. |
13
|
|
|
* |
14
|
|
|
* DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
15
|
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License along with DomainMOD. If not, see |
18
|
|
|
* http://www.gnu.org/licenses/. |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
//@formatter:off |
22
|
|
|
namespace DomainMOD; |
23
|
|
|
|
24
|
|
|
class Database |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
public $cnxx; |
28
|
|
|
public $log; |
29
|
|
|
private static $instance; |
30
|
|
|
|
31
|
|
|
private function __construct() |
32
|
|
|
{ |
33
|
|
|
$this->log = new Log('class.database'); |
34
|
|
|
|
35
|
|
|
$this->cnxx = new \PDO("mysql:host=" . DB_HOSTNAME . ";dbname=" . DB_NAME . ";charset=utf8", DB_USERNAME, DB_PASSWORD); |
36
|
|
|
$this->cnxx->exec("SET NAMES utf8"); |
37
|
|
|
$this->cnxx->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); |
38
|
|
|
$this->cnxx->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ); |
39
|
|
|
$this->cnxx->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public static function getInstance() |
43
|
|
|
{ |
44
|
|
|
if (!isset(self::$instance)) { |
45
|
|
|
$object = __CLASS__; |
46
|
|
|
self::$instance = new $object; |
47
|
|
|
} |
48
|
|
|
return self::$instance; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
} //@formatter:on |
52
|
|
|
|