tutelagesystems

Untitled

Dec 3rd, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2. /*******************************************************************************
  3. * Database_Mysql.php
  4. *
  5. * MySQL Wrapper to allow access into other databases (only with Seagull)
  6. *
  7. * Michael McMullen <[email protected]>
  8. *******************************************************************************/
  9.  
  10. require_once SGL_LIB_DIR .'/SGL/DB.php';
  11.  
  12. class Database_Mysql
  13. {
  14.    
  15.     var $username;
  16.     var $password;
  17.     var $hostname;
  18.     var $database;
  19.     var $dbh;
  20.     var $old_connection;
  21.    
  22.     function Database_Mysql($username, $password, $hostname, $database)
  23.     {
  24.         $this->username = $username;
  25.         $this->password = $password;
  26.         $this->hostname = $hostname;
  27.         $this->database = $database;
  28.     }
  29.  
  30.     function connect(&$dbh)
  31.     {
  32.         $this->old_connection = $dbh->dsn['dbsyntax'] .'://'. $dbh->dsn['username'] .':'. $dbh->dsn['password'] .'@'. $dbh->dsn['socket'] .'/'. $dbh->dsn['database'];
  33.  
  34.         // Load DataObjects
  35.         $options = &PEAR::getStaticProperty('DB_DataObject','options');
  36.  
  37.         // Overwrite Connection
  38.         $conn = 'mysql://'. $this->username .':'. $this->password .'@'. $this->hostname .'/'. $this->database;
  39.         $options['database'] = $conn;
  40.  
  41.         // Change Database
  42.         $dbh =& SGL_DB::singleton($conn);
  43.     }
  44.  
  45.     function disconnect(&$dbh)
  46.     {
  47.         // Load DataObjects
  48.         $options = &PEAR::getStaticProperty('DB_DataObject','options');
  49.  
  50.         // Overwrite Connection
  51.         $conn = $this->old_connection;
  52.         $options['database'] = $conn;
  53.  
  54.         $dbh =& SGL_DB::singleton($conn);
  55.     }
  56.    
  57. }
Advertisement
Add Comment
Please, Sign In to add comment