]> git.wh0rd.org - tt-rss.git/blob - classes/db/mysqli.php
e82f6630007fed0f211c00c20fff1bbb84e955b1
[tt-rss.git] / classes / db / mysqli.php
1 <?php
2 class Db_Mysqli implements IDb {
3 private $link;
4
5 function connect($host, $user, $pass, $db, $port) {
6 $this->link = mysqli_connect($host, $user, $pass, $db, $port);
7
8 if ($this->link) {
9 $this->init();
10
11 return $this->link;
12 } else {
13 die("Unable to connect to database (as $user to $host, database $db): " . mysqli_error());
14 }
15 }
16
17 function escape_string($s, $strip_tags = true) {
18 if ($strip_tags) $s = strip_tags($s);
19
20 return mysqli_real_escape_string($this->link, $s);
21 }
22
23 function query($query, $die_on_error = true) {
24 $result = mysqli_query($this->link, $query);
25 if (!$result) {
26 user_error("Query $query failed: " . ($this->link ? mysqli_error($this->link) : "No connection"),
27 $die_on_error ? E_USER_ERROR : E_USER_WARNING);
28 }
29
30 return $result;
31 }
32
33 function fetch_assoc($result) {
34 return mysqli_fetch_assoc($result);
35 }
36
37
38 function num_rows($result) {
39 return mysqli_num_rows($result);
40 }
41
42 function fetch_result($result, $row, $param) {
43 if (mysqli_data_seek($result, $row)) {
44 $line = mysqli_fetch_assoc($result);
45 return $line[$param];
46 } else {
47 return false;
48 }
49 }
50
51 function close() {
52 return mysqli_close($this->link);
53 }
54
55 function affected_rows($result) {
56 return mysqli_affected_rows($this->link);
57 }
58
59 function last_error() {
60 return mysqli_error();
61 }
62
63 function init() {
64 $this->query("SET time_zone = '+0:0'");
65
66 if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
67 $this->query("SET NAMES " . MYSQL_CHARSET);
68 }
69
70 return true;
71 }
72
73 }
74 ?>