]> git.wh0rd.org Git - tt-rss.git/blob - classes/db.php
Updated cache_images() to use _MIN_CACHE_IMAGE_SIZE constant when checking file size...
[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 (defined('_ENABLE_PDO') && _ENABLE_PDO && 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 : "");
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 reconnect() {
57                 $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : "");
58         }
59
60         function connect($host, $user, $pass, $db, $port) {
61                 //return $this->adapter->connect($host, $user, $pass, $db, $port);
62                 return ;
63         }
64
65         function escape_string($s, $strip_tags = true) {
66                 return $this->adapter->escape_string($s, $strip_tags);
67         }
68
69         function query($query, $die_on_error = true) {
70                 return $this->adapter->query($query, $die_on_error);
71         }
72
73         function fetch_assoc($result) {
74                 return $this->adapter->fetch_assoc($result);
75         }
76
77         function num_rows($result) {
78                 return $this->adapter->num_rows($result);
79         }
80
81         function fetch_result($result, $row, $param) {
82                 return $this->adapter->fetch_result($result, $row, $param);
83         }
84
85         function close() {
86                 return $this->adapter->close();
87         }
88
89         function affected_rows($result) {
90                 return $this->adapter->affected_rows($result);
91         }
92
93         function last_error() {
94                 return $this->adapter->last_error();
95         }
96
97 }
98 ?>