Guest User

Untitled

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