Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2.  
  3. class connection {
  4.     static protected $con;
  5.     protected $data;
  6.    
  7.     public function __construct($data) {
  8.         $this->def($data);
  9.     }
  10.    
  11.     protected function def($data) {
  12.         if (!is_array($data) or count($data) < 1) {
  13.             return false;
  14.         }
  15.        
  16.         $this->data['hostname'] = ($data['hostname'] != '' ? $data['hostname'] : '');
  17.         $this->data['username'] = ($data['username'] != '' ? $data['username'] : '');
  18.         $this->data['password'] = ($data['password'] != '' ? $data['password'] : '');
  19.         $this->data['database'] = ($data['database'] != '' ? $data['database'] : '');
  20.     }
  21.    
  22.     public function connect() {
  23.         if (count($this->data) < 1) {
  24.             return false;
  25.         }
  26.        
  27.         self::$con = mysqli_connect(
  28.                         $this->data['hostname'],
  29.                         $this->data['username'],
  30.                         $this->data['password'],
  31.                         $this->data['database']
  32.                     );
  33.        return true;
  34.     }
  35. }
  36.  
  37. $class = new connection(array(
  38.             'username' => '',
  39.             'hostname' => '',
  40.             'password' => '',
  41.             'database' => ''
  42.         ));
  43. $class->connect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement