PureMVC Database Class


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. class Database
  2. {
  3. private static $instance;
  4. private $dbName = "mcms";
  5. private $host = "localhost";
  6. private $username = "moroch";
  7. private $password = "w1d33y3";
  8. private $connected;
  9.  
  10. public function __construct()
  11. {
  12. }
  13.  
  14. public static function getInstance()
  15. {
  16. if (!self::$instance)
  17. {
  18. self::$instance = new Database();
  19. }
  20.  
  21. return self::$instance;
  22. }
  23.  
  24. public function connect()
  25. {
  26. try
  27. {
  28. $this->connected = mysql_connect($this->host,$this->username,$this->password);
  29. if (!$this->connected)
  30. throw new Exception("Could not connect to MySql server.");
  31. }
  32. catch (Exception $e)
  33. {
  34. die($e->getMessage());
  35. }
  36. }
  37.  
  38. public function selectDB()
  39. {
  40. mysql_select_db($this->dbName);
  41. }
  42.  
  43. public function execute($sql)
  44. {
  45. return mysql_query($sql);
  46. }
  47. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.