Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class D {
- private static $instance;
- private $connected=false,$db,$mf;
- public static function getInstance() {
- if (!isset(self::$instance)) {
- self::$instance = new self();
- }
- return self::$instance;
- }
- public function connect() {
- $mf = MF::getInstance();
- $this->r = R::getInstance();
- if($this->connected == false) {
- $this->db = new PDO('mysql:host='.$this->r->mysql_host.';dbname='.$this->r->mysql_database, $this->r->mysql_username, $this->r->mysql_password);
- if($this->db == true) {
- $this->connected = true;
- $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }else{
- $this->mf->report('Unable to connect to database',2);
- }
- }else{
- $this->mf->report('Connection already made.');
- }
- }
- public function query($sql) {
- try {
- $q = $this->db->query($sql);
- }
- catch(PDOException $e) {
- trigger_error('<br>Regel: '.$e->getLine().'<br>
- Bestand: '.$e->getFile().'<br>
- Foutmelding: '.$e->getMessage().'<br>SQL: '.$sql,E_USER_ERROR);
- die();
- }
- return $q;
- }
- }
Add Comment
Please, Sign In to add comment