]> git.wh0rd.org Git - tt-rss.git/blob - classes/db.php
Merge branch 'master' into pdo
[tt-rss.git] / classes / db.php
1 <?php
2 class Db implements IDb {
3         private static $instance;
4         private $adapter;
5         private $link;
6
7         private function __construct() {
8
9                 $er = error_reporting(E_ALL);
10
11                 if (class_exists("PDO")) {
12                         $this->adapter = new Db_PDO();
13                 } else {
14                         switch (DB_TYPE) {
15                         case "mysql":
16                                 if (function_exists("mysqli_connect")) {
17                                         $this->adapter = new Db_Mysqli();
18                                 } else {
19                                         $this->adapter = new Db_Mysql();
20                                 }
21                                 break;
22                         case "pgsql":
23                                 $this->adapter = new Db_Pgsql();
24                                 break;
25                         default:
26                                 die("Unknown DB_TYPE: " . DB_TYPE);
27                         }
28                 }
29
30                 if (!$this->adapter) die("Error initializing database adapter for " . DB_TYPE);
31
32                 $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : false);
33
34                 if (!$this->link) {
35                         die("Error connecting through adapter: " . $this->adapter->last_error());
36                 }
37
38                 error_reporting($er);
39         }
40
41         private function __clone() {
42                 //
43         }
44
45         public static function get() {
46                 if (self::$instance == null)
47                         self::$instance = new self();
48
49                 return self::$instance;
50         }
51
52         static function quote($str){
53                 return("'$str'");
54         }
55
56         function connect($host, $user, $pass, $db, $port) {
57                 //return $this->adapter->connect($host, $user, $pass, $db, $port);
58                 return ;
59         }
60
61         function escape_string($s, $strip_tags = true) {
62                 return $this->adapter->escape_string($s, $strip_tags);
63         }
64
65         function query($query, $die_on_error = true) {
66                 return $this->adapter->query($query, $die_on_error);
67         }
68
69         function fetch_assoc($result) {
70                 return $this->adapter->fetch_assoc($result);
71         }
72
73         function num_rows($result) {
74                 return $this->adapter->num_rows($result);
75         }
76
77         function fetch_result($result, $row, $param) {
78                 return $this->adapter->fetch_result($result, $row, $param);
79         }
80
81         function close() {
82                 return $this->adapter->close();
83         }
84
85         function affected_rows($result) {
86                 return $this->adapter->affected_rows($result);
87         }
88
89         function last_error() {
90                 return $this->adapter->last_error();
91         }
92
93 }
94 ?>