]> git.wh0rd.org - tt-rss.git/blob - classes/db/mysql.php
fa97dcff16d9af59d931abf5cfb270c21afc556d
[tt-rss.git] / classes / db / mysql.php
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);
7 if ($this->link) {
8 $result = mysql_select_db($db, $this->link);
9 if (!$result) {
10 die("Can't select DB: " . mysql_error($this->link));
11 }
12 return $this->link;
13 } else {
14 die("Unable to connect to database (as $user to $host, database $db): " . mysql_error());
15 }
16 }
17
18 function escape_string($s, $strip_tags = true) {
19 return mysql_real_escape_string($s, $this->link);
20 }
21
22 function query($query, $die_on_error = true) {
23 $result = mysql_query($query, $this->link);
24 if (!$result) {
25 $query = htmlspecialchars($query);
26 if ($die_on_error) {
27 die("Query <i>$query</i> failed: " . ($this->link ? mysql_error($link) : "No connection"));
28 }
29 }
30 return $result;
31 }
32
33 function fetch_assoc($result) {
34 return mysql_fetch_assoc($result);
35 }
36
37
38 function num_rows($result) {
39 return mysql_num_rows($result);
40 }
41
42 function fetch_result($result, $row, $param) {
43 return mysql_result($result, $row, $param);
44 }
45
46 function close() {
47 return mysql_close($this->link);
48 }
49
50 function affected_rows($result) {
51 return mysql_affected_rows($this->link);
52 }
53
54 function last_error() {
55 return mysql_affected_rows($this->link);
56 }
57
58 function init() {
59 $this->query("SET time_zone = '+0:0'");
60
61 if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
62 $this->query("SET NAMES " . MYSQL_CHARSET);
63 }
64
65 return true;
66 }
67
68 }
69 ?>