]>
Commit | Line | Data |
---|---|---|
95947917 AD |
1 | <?php |
2 | class Db_Mysql implements IDb { | |
3 | private $link; | |
4 | ||
5 | function connect($host, $user, $pass, $db, $port) { | |
6 | $this->link = mysql_connect($host, $user, $pass); | |
eefaa2df | 7 | |
95947917 AD |
8 | if ($this->link) { |
9 | $result = mysql_select_db($db, $this->link); | |
10 | if (!$result) { | |
11 | die("Can't select DB: " . mysql_error($this->link)); | |
12 | } | |
404e2e36 AD |
13 | |
14 | $this->init(); | |
15 | ||
95947917 AD |
16 | return $this->link; |
17 | } else { | |
18 | die("Unable to connect to database (as $user to $host, database $db): " . mysql_error()); | |
19 | } | |
20 | } | |
21 | ||
22 | function escape_string($s, $strip_tags = true) { | |
ae35bb87 AD |
23 | if ($strip_tags) $s = strip_tags($s); |
24 | ||
95947917 AD |
25 | return mysql_real_escape_string($s, $this->link); |
26 | } | |
27 | ||
28 | function query($query, $die_on_error = true) { | |
38f43970 | 29 | $result = @mysql_query($query, $this->link); |
95947917 | 30 | if (!$result) { |
38f43970 AD |
31 | $error = @mysql_error($this->link); |
32 | ||
33 | @mysql_query("ROLLBACK", $this->link); | |
34 | user_error("Query $query failed: " . ($this->link ? $error : "No connection"), | |
aca75cb5 | 35 | $die_on_error ? E_USER_ERROR : E_USER_WARNING); |
95947917 AD |
36 | } |
37 | return $result; | |
38 | } | |
39 | ||
40 | function fetch_assoc($result) { | |
41 | return mysql_fetch_assoc($result); | |
42 | } | |
43 | ||
44 | ||
45 | function num_rows($result) { | |
46 | return mysql_num_rows($result); | |
47 | } | |
48 | ||
49 | function fetch_result($result, $row, $param) { | |
50 | return mysql_result($result, $row, $param); | |
51 | } | |
52 | ||
53 | function close() { | |
54 | return mysql_close($this->link); | |
55 | } | |
56 | ||
57 | function affected_rows($result) { | |
58 | return mysql_affected_rows($this->link); | |
59 | } | |
60 | ||
61 | function last_error() { | |
ae35bb87 | 62 | return mysql_error(); |
95947917 AD |
63 | } |
64 | ||
ba68b681 AD |
65 | function init() { |
66 | $this->query("SET time_zone = '+0:0'"); | |
67 | ||
68 | if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) { | |
69 | $this->query("SET NAMES " . MYSQL_CHARSET); | |
70 | } | |
71 | ||
72 | return true; | |
73 | } | |
74 | ||
95947917 AD |
75 | } |
76 | ?> |