Advertisement
terorama

WP / test / mysqli / db.inc.php

May 29th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2.  
  3. class DBConn implements IDBConn {
  4.    private $_db=0;
  5.    
  6.    private $DB_HOST;
  7.    private $DB_USER;
  8.    private $DB_PASSWORD;
  9.    private $DB_NAME;
  10.    
  11.    //----------------------------------
  12.    public function connect() {
  13.    
  14.       $this->_db = @new mysqli ($this->DB_HOST, $this->DB_USER, $this->DB_PASSWORD, $this->DB_NAME );
  15.      
  16.       if ($this->_db->connect_errno) {
  17.      
  18.          throw new Exception('connection error '.$this->_db->connect_error);
  19.       }
  20.  
  21.    }
  22.    
  23.    //----------------------------------
  24.    public function set($DB_HOST, $DB_USER, $DB_PASSWORD, $DB_NAME) {
  25.    
  26.       $this->DB_HOST = $DB_HOST;
  27.       $this->DB_USER = $DB_USER;
  28.       $this->DB_PASSWORD = $DB_PASSWORD;
  29.       $this->DB_NAME = $DB_NAME;
  30.    }
  31.    
  32.    //----------------------------------
  33.    public function get() {
  34.       if ($this->_db===0) {
  35.          $this->connect();
  36.       }
  37.      
  38.       return $this->_db;
  39.    }
  40. }
  41.  
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement