()
| 17 | // Connect to MySQL. |
| 18 | private static $conn = null; |
| 19 | private static function connect() { |
| 20 | if (self::$conn) { |
| 21 | return self::$conn; |
| 22 | } else { |
| 23 | self::$conn = new mysqli( |
| 24 | $GLOBALS['DB_HOST'], |
| 25 | $GLOBALS['DB_USERNAME'], |
| 26 | $GLOBALS['DB_PASSWORD'], |
| 27 | $GLOBALS['DB_NAME'], |
| 28 | $GLOBALS['DB_PORT'], |
| 29 | $GLOBALS['DB_SOCKET'] |
| 30 | ); |
| 31 | if(self::$conn->connect_error){ |
| 32 | throw new Exception( |
| 33 | 'Cannot connect to database: ' |
| 34 | .self::$conn->connect_error |
| 35 | ); |
| 36 | } |
| 37 | return self::$conn; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Query helper. |