SHARE
TWEET

Untitled

a guest Jun 14th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  35.         $this->theQuery = $query;
  36.         return mysql_query($query, $this->link);
  37.  
  38.     }
  39.  
  40.     //Function: fetchArray, Purpose: Get array of query results
  41.     function fetchArray($result) {
  42.  
  43.         return mysql_fetch_array($result);
  44.  
  45.     }
  46.  
  47.     //Function: close, Purpose: Close the connection
  48.     function close() {
  49.  
  50.         mysql_close($this->link);
  51.  
  52.     }
  53. }
  54. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top