]>
Commit | Line | Data |
---|---|---|
95947917 AD |
1 | <?php |
2 | class Db implements IDb { | |
3 | private static $instance; | |
4 | private $adapter; | |
404e2e36 | 5 | private $link; |
95947917 AD |
6 | |
7 | private function __construct() { | |
8 | switch (DB_TYPE) { | |
9 | case "mysql": | |
10 | $this->adapter = new Db_Mysql(); | |
11 | break; | |
12 | case "pgsql": | |
13 | $this->adapter = new Db_Pgsql(); | |
14 | break; | |
15 | default: | |
404e2e36 | 16 | user_error("Unknown DB_TYPE: " . DB_TYPE); |
95947917 AD |
17 | } |
18 | ||
404e2e36 AD |
19 | $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT); |
20 | ||
95947917 AD |
21 | } |
22 | ||
23 | private function __clone() { | |
24 | // | |
25 | } | |
26 | ||
27 | public static function get() { | |
28 | if (self::$instance == null) | |
29 | self::$instance = new self(); | |
30 | ||
31 | return self::$instance; | |
32 | } | |
33 | ||
34 | static function quote($str){ | |
35 | return("'$str'"); | |
36 | } | |
37 | ||
ba68b681 AD |
38 | function init() { |
39 | // | |
40 | } | |
41 | ||
95947917 AD |
42 | function connect($host, $user, $pass, $db, $port) { |
43 | //return $this->adapter->connect($host, $user, $pass, $db, $port); | |
404e2e36 | 44 | return $this->link; |
95947917 AD |
45 | } |
46 | ||
47 | function escape_string($s, $strip_tags = true) { | |
48 | return $this->adapter->escape_string($s, $strip_tags); | |
49 | } | |
50 | ||
51 | function query($query, $die_on_error = true) { | |
52 | return $this->adapter->query($query, $die_on_error); | |
53 | } | |
54 | ||
55 | function fetch_assoc($result) { | |
56 | return $this->adapter->fetch_assoc($result); | |
57 | } | |
58 | ||
59 | function num_rows($result) { | |
60 | return $this->adapter->num_rows($result); | |
61 | } | |
62 | ||
63 | function fetch_result($result, $row, $param) { | |
64 | return $this->adapter->fetch_result($result, $row, $param); | |
65 | } | |
66 | ||
67 | function close() { | |
68 | return $this->adapter->close(); | |
69 | } | |
70 | ||
71 | function affected_rows($result) { | |
72 | return $this->adapter->affected_rows($result); | |
73 | } | |
74 | ||
75 | function last_error() { | |
76 | return $this->adapter->last_error(); | |
77 | } | |
78 | ||
79 | } | |
80 | ?> |