| Total Complexity | 5 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 14 | class Connection |
||
| 15 | { |
||
| 16 | private static $con = null; |
||
| 17 | |||
| 18 | private function __construct() |
||
| 19 | { |
||
| 20 | } |
||
| 21 | |||
| 22 | public static function getPrefix() |
||
| 23 | { |
||
| 24 | return Credentials::get('prefix'); |
||
|
|
|||
| 25 | } |
||
| 26 | |||
| 27 | public static function get() |
||
| 28 | { |
||
| 29 | if (!self::$con) { |
||
| 30 | self::$con = new \PDO('mysql:host=localhost; dbname='.Credentials::get('database'), |
||
| 31 | Credentials::get('username'), |
||
| 32 | Credentials::get('password') |
||
| 33 | ); |
||
| 34 | self::$con->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false); |
||
| 35 | // which tells PDO to disable emulated prepared statements and use real prepared statements. |
||
| 36 | // This makes sure the statement and the values aren't parsed by PHP before sending it to the |
||
| 37 | // MySQL server (giving a possible attacker no chance to inject malicious SQL). |
||
| 38 | self::$con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
||
| 39 | } |
||
| 40 | |||
| 41 | return self::$con; |
||
| 42 | } |
||
| 43 | |||
| 44 | private function __clone() |
||
| 46 | } |
||
| 47 | } |
||
| 48 |