Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class connection {
- static protected $con;
- protected $data;
- public function __construct($data) {
- $this->def($data);
- }
- protected function def($data) {
- if (!is_array($data) or count($data) < 1) {
- return false;
- }
- $this->data['hostname'] = ($data['hostname'] != '' ? $data['hostname'] : '');
- $this->data['username'] = ($data['username'] != '' ? $data['username'] : '');
- $this->data['password'] = ($data['password'] != '' ? $data['password'] : '');
- $this->data['database'] = ($data['database'] != '' ? $data['database'] : '');
- }
- public function connect() {
- if (count($this->data) < 1) {
- return false;
- }
- self::$con = mysqli_connect(
- $this->data['hostname'],
- $this->data['username'],
- $this->data['password'],
- $this->data['database']
- );
- return true;
- }
- }
- $class = new connection(array(
- 'username' => '',
- 'hostname' => '',
- 'password' => '',
- 'database' => ''
- ));
- $class->connect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement