Guest User

Untitled

a guest
Jun 8th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. Class Model
  5. {
  6. protected static $Instance = null;
  7. public $DB;
  8.  
  9. public static function getInstance()
  10. {
  11. if(self::$Instance == null)
  12. self::$Instance = new Model;
  13. return self::$Instance;
  14. }
  15.  
  16. private function __construct(){
  17. $pr = Spyc::YAMLLoad('config/parameters.yml');
  18. $this->connect($pr);
  19. }
  20.  
  21. public function connect(Array $pr)
  22. {
  23. $host = $pr['database']['host'];
  24. $dbname = $pr['database']['dbname'];
  25. $user = $pr['database']['user'];
  26. $pass = $pr['database']['pass'];
  27. try {
  28. $this->DB = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
  29. }
  30. catch(PDOException $e) {
  31. echo $e->getMessage();
  32. }
  33. $this->DB->query("SET NAMES 'utf8'");
  34. $this->DB->query("SET CHARACTER SET 'utf8'");
  35. $this->DB->query("SET SESSION collation_connection = 'utf8_general_ci'");
  36. }
  37.  
  38. public function __destruct() {
  39. $this->DB = null;
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment