PHP MySQLi DB_Conn Wrapper Class

PHP

Public Domain

Simple MySQLi connection handler class for PHP

Download (right click, save as, rename as appropriate)

Embed

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class db_conn{
	private $db = false;
	
	function __construct($connect = false){
		if($connect)
			$this->connect();
	}
	
	function connect(){
		$this->db = new mysqli(_DB_HOST_, _DB_USER_, _DB_PASS_);
		if(!$this->db)
			header('Location: db_err.php');
	}
	
	function query($query){
		if(!$this->db)
			$this->connect();
			
		return $this->db->query($query);
	}
	
	function escape($value){
		if(!$this->db)
			$this->connect();

		return $this->db->real_escape_string($value);
	}
	
	function insert_id(){
		if(!$this->db){
			$this->connect();
			return false;
		}else
			return $this->db->insert_id;
	}
}