Guest User

Untitled

a guest
Jan 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. class D {
  2. private static $instance;
  3. private $connected=false,$db,$mf;
  4.  
  5. public static function getInstance() {
  6. if (!isset(self::$instance)) {
  7. self::$instance = new self();
  8. }
  9. return self::$instance;
  10. }
  11.  
  12.  
  13. public function connect() {
  14. $mf = MF::getInstance();
  15. $this->r = R::getInstance();
  16. if($this->connected == false) {
  17. $this->db = new PDO('mysql:host='.$this->r->mysql_host.';dbname='.$this->r->mysql_database, $this->r->mysql_username, $this->r->mysql_password);
  18. if($this->db == true) {
  19. $this->connected = true;
  20. $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  21. }else{
  22. $this->mf->report('Unable to connect to database',2);
  23. }
  24. }else{
  25. $this->mf->report('Connection already made.');
  26. }
  27. }
  28.  
  29. public function query($sql) {
  30. try {
  31. $q = $this->db->query($sql);
  32. }
  33. catch(PDOException $e) {
  34. trigger_error('<br>Regel: '.$e->getLine().'<br>
  35. Bestand: '.$e->getFile().'<br>
  36. Foutmelding: '.$e->getMessage().'<br>SQL: '.$sql,E_USER_ERROR);
  37. die();
  38. }
  39. return $q;
  40. }
  41. }
Add Comment
Please, Sign In to add comment