Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // _____
- // ___ _ __|___ /_ __
- // / __| '_ \ |_ \ \/ /
- // \__ \ |_) |__) > <
- // |___/ .__/____/_/\_\
- // |_| info@sp3x.de
- //
- // @author sp3x
- // @copyright sp3x / sp3x.de
- // @license All rights reserved
- // @version $Revision 1 $
- // @date $17.09.2009 $
- //
- class Database
- {
- //
- // MySQLi Object
- // @var mysqli
- //
- private $hMySQLi;
- //
- // Debugging mode
- // @var boolean
- //
- private $debug;
- //
- // MySQLi Result object
- // @var MySQLi::Result
- //
- private $result;
- //
- // MySQLi Statement object
- // @var MySQLi::STMT
- //
- private $stmt;
- //
- // Parameters for prepared statements
- // @var array
- //
- private $params;
- //
- // Database constructor
- // -----------------------------------------------------
- // @param boolean Debugging
- //
- public function __construct($debug = false)
- {
- $this->debug = $debug;
- }
- //
- // Connect to mysql database
- // -----------------------------------------------------
- // @param string Hostname
- // @param string Username
- // @param string Password
- // @param integer Port
- // @param boolean Persistente connection
- //
- public function connect($host = '127.0.0.1', $user = 'root', $pass = '', $port = 3306,
- $pconn = false)
- {
- if($pconn)
- $host = 'p:'.$host;
- $this->hMySQLi = @new mysqli($host, $user, $pass, '', $port);
- if(!$this->hMySQLi->connect_error)
- return true;
- $this->debug();
- return false;
- }
- public function disconnect()
- {
- @$this->hMySQLi->close();
- unset($this->hMySQLi);
- $this->hMySQLi = null;
- }
- //
- // Returns error and errno if an error occurs
- // -----------------------------------------------------
- // @param array error[0] and errno[1]
- //
- public function error()
- {
- if($this->hMySQLi->connect_error)
- return array($this->hMySQLi->connect_error, $this->hMySQLi->connect_errno);
- else
- return array($this->hMySQLi->error, $this->hMySQLi->errno);
- }
- //
- // Selects specified default database for querys
- // -----------------------------------------------------
- // @param string Database name
- //
- public function dbname($dbName)
- {
- $retVal = @$this->hMySQLi->select_db($dbName);
- $this->debug();
- return $retVal;
- }
- //
- // -----------------------------------------------------
- //
- //
- //
- //
- //
- public function query()
- {
- }
- //
- // -----------------------------------------------------
- //
- //
- //
- //
- public function fetch()
- {
- }
- //
- // -----------------------------------------------------
- //
- //
- //
- //
- public function fetchAll()
- {
- }
- //
- // Prepares query for execution
- // -----------------------------------------------------
- // @param string Query
- //
- public function prepare($query)
- {
- if($this->stmt = $this->hMySQLi->prepare($query))
- return true;
- $debug();
- return false;
- }
- //
- // Starts transaction if database engine
- // supports it
- // -----------------------------------------------------
- //
- public function transaction()
- {
- $this->hMySQLi->autocommit(false);
- }
- //
- // Rollbacks active transaction
- // -----------------------------------------------------
- //
- public function rollback()
- {
- $this->hMySQLi->rollback();
- $this->hMySQLi->autocommit(true);
- }
- //
- // Commits active transaction
- // -----------------------------------------------------
- //
- public function commit()
- {
- $this->hMySQLi->commit();
- $this->hMySQLi->autocommit(true);
- }
- //
- // Debugging function displays error messages if an error
- // occurs
- // -----------------------------------------------------
- //
- private function debug()
- {
- if($this->debug)
- {
- $error = $this->error();
- if($error[1])
- {
- echo "<pre>MySQLi - Debugging Mode:\n------------------------\n";
- echo "Error: {$error[0]}\nErrno: {$error[1]}\n\n</pre>";
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement