]> git.wh0rd.org - tt-rss.git/blob - classes/db.php
remove support for legacy mysql driver
[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 $this->adapter = new Db_Mysqli();
17 break;
18 case "pgsql":
19 $this->adapter = new Db_Pgsql();
20 break;
21 default:
22 die("Unknown DB_TYPE: " . DB_TYPE);
23 }
24 }
25
26 if (!$this->adapter) die("Error initializing database adapter for " . DB_TYPE);
27
28 $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : "");
29
30 if (!$this->link) {
31 die("Error connecting through adapter: " . $this->adapter->last_error());
32 }
33
34 error_reporting($er);
35 }
36
37 private function __clone() {
38 //
39 }
40
41 public static function get() {
42 if (self::$instance == null)
43 self::$instance = new self();
44
45 return self::$instance;
46 }
47
48 static function quote($str){
49 return("'$str'");
50 }
51
52 function reconnect() {
53 $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : "");
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 function last_query_error() {
94 return $this->adapter->last_query_error();
95 }
96 }
97 ?>