]>
git.wh0rd.org - tt-rss.git/blob - classes/db.php
2 class Db
implements IDb
{
3 private static $instance;
7 private function __construct() {
9 $er = error_reporting(E_ALL
);
11 if (defined('_ENABLE_PDO') && _ENABLE_PDO
&& class_exists("PDO")) {
12 $this->adapter
= new Db_PDO();
16 $this->adapter
= new Db_Mysqli();
19 $this->adapter
= new Db_Pgsql();
22 die("Unknown DB_TYPE: " . DB_TYPE
);
26 if (!$this->adapter
) {
27 print("Error initializing database adapter for " . DB_TYPE
);
31 $this->link
= $this->adapter
->connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
, defined('DB_PORT') ? DB_PORT
: "");
34 print("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 reconnect() {
57 $this->link
= $this->adapter
->connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
, defined('DB_PORT') ? DB_PORT
: "");
60 function connect($host, $user, $pass, $db, $port) {
61 //return $this->adapter->connect($host, $user, $pass, $db, $port);
65 function escape_string($s, $strip_tags = true) {
66 return $this->adapter
->escape_string($s, $strip_tags);
69 function query($query, $die_on_error = true) {
70 return $this->adapter
->query($query, $die_on_error);
73 function fetch_assoc($result) {
74 return $this->adapter
->fetch_assoc($result);
77 function num_rows($result) {
78 return $this->adapter
->num_rows($result);
81 function fetch_result($result, $row, $param) {
82 return $this->adapter
->fetch_result($result, $row, $param);
86 return $this->adapter
->close();
89 function affected_rows($result) {
90 return $this->adapter
->affected_rows($result);
93 function last_error() {
94 return $this->adapter
->last_error();
97 function last_query_error() {
98 return $this->adapter
->last_query_error();