Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database extends MySQLi
- {
- private $host, $user, $pass, $name;
- private $connection, $result;
- public function __construct($host, $username, $password, $dbname)
- {
- $this->host = $host;
- $this->user = $username;
- $this->pass = $password;
- $this->name = $dbname;
- $this->_connect();
- }
- private function _connect()
- {
- $this->connection = new MySQLi($this->host, $this->user, $this->pass, $this->name);
- }
- public function query($sql)
- {
- $this->result = $this->connection->query($sql);
- return $this;
- }
- public function fetchAll()
- {
- $obj = new stdClass();
- while($fetch = $this->result->fetch_object())
- {
- $obj = $fetch;
- }
- return $obj;
- }
- }
- $db = new Database('localhost', 'root', '', 'test_db');
- $db->query("SELECT * FROM `tabelle`)->fetchAll();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement