Guest User

Untitled

a guest
Mar 12th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////////////
  2. // Class: DbConnector
  3. // Purpose: Connect to a database, MySQL version
  4. ///////////////////////////////////////////////////////////////////////////////////////
  5. require_once 'SystemComponent.php';
  6.  
  7. class DbConnector extends SystemComponent {
  8.  
  9. var $theQuery;
  10. var $link;
  11.  
  12. //*** Function: DbConnector, Purpose: Connect to the database ***
  13. function DbConnector(){
  14.  
  15. // Load settings from parent class
  16. $settings = SystemComponent::getSettings();
  17.  
  18. // Get the main settings from the array we just loaded
  19. $host = $settings['dbhost'];
  20. $db = $settings['dbname'];
  21. $user = $settings['dbusername'];
  22. $pass = $settings['dbpassword'];
  23.  
  24. // Connect to the database
  25. $this->link = mysql_connect($host, $user, $pass);
  26. mysql_select_db($db);
  27. register_shutdown_function(array(&$this, 'close'));
  28.  
  29. }
  30.  
  31. //*** Function: query, Purpose: Execute a database query ***
  32. function query($query) {
  33.  
  34. $this->theQuery = $query;
  35. return mysql_query($query, $this->link);
  36.  
  37. }
  38.  
  39. //*** Function: fetchArray, Purpose: Get array of query results ***
  40. function fetchArray($result) {
  41.  
  42. return mysql_fetch_array($result);
  43.  
  44. }
  45.  
  46. //*** Function: close, Purpose: Close the connection ***
  47. function close() {
  48.  
  49. mysql_close($this->link);
  50.  
  51. }
  52.  
  53.  
  54. }
  55. ?>
Add Comment
Please, Sign In to add comment