2 class Db implements IDb {
3 private static $instance;
7 private function __construct() {
9 $er = error_reporting(E_ALL);
11 if (class_exists("PDO")) {
12 $this->adapter = new Db_PDO();
16 if (function_exists("mysqli_connect")) {
17 $this->adapter = new Db_Mysqli();
19 $this->adapter = new Db_Mysql();
23 $this->adapter = new Db_Pgsql();
26 die("Unknown DB_TYPE: " . DB_TYPE);
30 if (!$this->adapter) die("Error initializing database adapter for " . DB_TYPE);
32 $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : false);
35 die("Error connecting through adapter: " . $this->adapter->last_error());
41 private function __clone() {
45 public static function get() {
46 if (self::$instance == null)
47 self::$instance = new self();
49 return self::$instance;
52 static function quote($str){
56 function connect($host, $user, $pass, $db, $port) {
57 //return $this->adapter->connect($host, $user, $pass, $db, $port);
61 function escape_string($s, $strip_tags = true) {
62 return $this->adapter->escape_string($s, $strip_tags);
65 function query($query, $die_on_error = true) {
66 return $this->adapter->query($query, $die_on_error);
69 function fetch_assoc($result) {
70 return $this->adapter->fetch_assoc($result);
73 function num_rows($result) {
74 return $this->adapter->num_rows($result);
77 function fetch_result($result, $row, $param) {
78 return $this->adapter->fetch_result($result, $row, $param);
82 return $this->adapter->close();
85 function affected_rows($result) {
86 return $this->adapter->affected_rows($result);
89 function last_error() {
90 return $this->adapter->last_error();