]>
Commit | Line | Data |
---|---|---|
95947917 AD |
1 | <?php |
2 | class Db implements IDb { | |
3 | private static $instance; | |
4 | private $adapter; | |
404e2e36 | 5 | private $link; |
99bda9cc | 6 | private $pdo; |
95947917 AD |
7 | |
8 | private function __construct() { | |
e441b583 AD |
9 | |
10 | $er = error_reporting(E_ALL); | |
11 | ||
99bda9cc | 12 | switch (DB_TYPE) { |
e441b583 | 13 | case "mysql": |
e54eb40a | 14 | $this->adapter = new Db_Mysqli(); |
e441b583 AD |
15 | break; |
16 | case "pgsql": | |
17 | $this->adapter = new Db_Pgsql(); | |
18 | break; | |
19 | default: | |
20 | die("Unknown DB_TYPE: " . DB_TYPE); | |
95947917 AD |
21 | } |
22 | ||
3c111597 AD |
23 | if (!$this->adapter) { |
24 | print("Error initializing database adapter for " . DB_TYPE); | |
25 | exit(100); | |
26 | } | |
e441b583 | 27 | |
99bda9cc AD |
28 | $db_port = defined(DB_PORT) ? ';port='.DB_PORT : ''; |
29 | ||
30 | $this->pdo = new PDO(DB_TYPE . ':dbname='.DB_NAME.';host='.DB_HOST.$db_port, | |
31 | DB_USER, | |
32 | DB_PASS); | |
33 | ||
34 | if (!$this->pdo) { | |
35 | print("Error connecting via PDO."); | |
36 | exit(101); | |
37 | } | |
38 | ||
1daf0f75 | 39 | $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : ""); |
e441b583 AD |
40 | |
41 | if (!$this->link) { | |
3c111597 AD |
42 | print("Error connecting through adapter: " . $this->adapter->last_error()); |
43 | exit(101); | |
e441b583 AD |
44 | } |
45 | ||
46 | error_reporting($er); | |
95947917 AD |
47 | } |
48 | ||
49 | private function __clone() { | |
50 | // | |
51 | } | |
52 | ||
53 | public static function get() { | |
54 | if (self::$instance == null) | |
55 | self::$instance = new self(); | |
56 | ||
57 | return self::$instance; | |
58 | } | |
59 | ||
8adb3ec4 AD |
60 | public static function pdo() { |
61 | if (self::$instance == null) | |
62 | self::$instance = new self(); | |
63 | ||
64 | return self::$instance->pdo; | |
65 | } | |
66 | ||
95947917 AD |
67 | static function quote($str){ |
68 | return("'$str'"); | |
69 | } | |
70 | ||
e2cf81e2 AD |
71 | function reconnect() { |
72 | $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : ""); | |
73 | } | |
74 | ||
95947917 AD |
75 | function connect($host, $user, $pass, $db, $port) { |
76 | //return $this->adapter->connect($host, $user, $pass, $db, $port); | |
6322ac79 | 77 | return ; |
95947917 AD |
78 | } |
79 | ||
80 | function escape_string($s, $strip_tags = true) { | |
81 | return $this->adapter->escape_string($s, $strip_tags); | |
82 | } | |
83 | ||
84 | function query($query, $die_on_error = true) { | |
85 | return $this->adapter->query($query, $die_on_error); | |
86 | } | |
87 | ||
88 | function fetch_assoc($result) { | |
89 | return $this->adapter->fetch_assoc($result); | |
90 | } | |
91 | ||
92 | function num_rows($result) { | |
93 | return $this->adapter->num_rows($result); | |
94 | } | |
95 | ||
96 | function fetch_result($result, $row, $param) { | |
97 | return $this->adapter->fetch_result($result, $row, $param); | |
98 | } | |
99 | ||
100 | function close() { | |
101 | return $this->adapter->close(); | |
102 | } | |
103 | ||
104 | function affected_rows($result) { | |
105 | return $this->adapter->affected_rows($result); | |
106 | } | |
107 | ||
108 | function last_error() { | |
109 | return $this->adapter->last_error(); | |
110 | } | |
111 | ||
977cea14 AD |
112 | function last_query_error() { |
113 | return $this->adapter->last_query_error(); | |
114 | } | |
ea79a0e0 | 115 | } |