2013-11-24 22:16:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class MysqlConnector {
|
|
|
|
private $connection = null;
|
|
|
|
private static $instance = null;
|
|
|
|
|
|
|
|
private function __construct() {
|
|
|
|
$this->connect();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function connect() {
|
2014-08-30 22:29:46 +02:00
|
|
|
try {
|
|
|
|
$this->connection = new PDO('mysql:host='.MYSQL_HOST.';dbname='.MYSQL_DB, MYSQL_LOGIN, MYSQL_PASSWORD);
|
|
|
|
$this->connection->query('SET NAMES utf8');
|
|
|
|
} catch (Exception $e) {
|
|
|
|
exit ('Unable to access database.');
|
|
|
|
}
|
2013-11-24 22:16:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function disconnect() {
|
|
|
|
$this->connection = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getConnection() {
|
|
|
|
return $this->connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getInstance() {
|
2014-08-30 22:29:46 +02:00
|
|
|
|
2013-11-24 22:16:32 +01:00
|
|
|
if (self::$instance === null) {
|
2014-08-30 22:29:46 +02:00
|
|
|
self::$instance = new self();
|
2013-11-24 22:16:32 +01:00
|
|
|
}
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
}
|