Posted By

ghwilson4456 on 10/09/08


Tagged

mysql database php textmate PureMVC


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

oso96_2000


PureMVC Database Class


 / Published in: PHP
 

  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
Posted By: AKtivX on October 9, 2008

Thank you for the contribution, but I am unsure what you mean by Pure MVC... MVC is a design pattern that uses 3 components Model... which is generally a class definition of database table, the View which isused to handle the display of the data provided by the model, and of course the controller, which basically handles requests and routes the request to the proper controller and loads the correct view.. This class here, is a a singleton .. which means it will only allow a single instance of the object to exist at any given time. This pattern is often used in an MVC architecture, but it is not really anything to do with MVC as a whole... Good code though, so please dont take this the wrong way... very useful.

Cheers

Posted By: ghwilson4456 on January 13, 2009

Maybe I should have come up with a better title or offered a description. Frankly, the code was meant for my developers particular usage alone and should probably have been set to private (I'm somewhat new to Snipplr.com). This code is meant for my Flex developers using PureMVC and WebORB. It's usage is for working with the AS3 code generated by WebORB's management tool and our workflow.

You need to login to post a comment.