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