Database::getInstance()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
namespace GJClasses;
3
4
class Database
5
{
6
    public $cnxx;
7
    private static $instance;
8
9
    private function __construct()
10
    {
11
        $this->cnxx = new \PDO("mysql:host=" . GJC_DB_HOSTNAME . ";dbname=" . GJC_DB_NAME . ";charset=utf8", GJC_DB_USERNAME, GJC_DB_PASSWORD);
12
        $this->cnxx->exec("SET NAMES utf8");
13
        $this->cnxx->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
14
        $this->cnxx->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_OBJ);
15
        $this->cnxx->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
16
    }
17
18
    public static function getInstance()
19
    {
20
        if (!isset(self::$instance)) {
21
            $object = __CLASS__;
22
            self::$instance = new $object;
23
        }
24
        return self::$instance;
25
    }
26
}
27