]>
git.wh0rd.org - tt-rss.git/blob - classes/db/mysql.php
2 class Db_Mysql
implements IDb
{
6 function connect($host, $user, $pass, $db, $port) {
7 $this->link
= mysql_connect($host, $user, $pass);
10 $result = mysql_select_db($db, $this->link
);
12 die("Can't select DB: " . mysql_error($this->link
));
19 die("Unable to connect to database (as $user to $host, database $db): " . mysql_error());
23 function escape_string($s, $strip_tags = true) {
24 if ($strip_tags) $s = strip_tags($s);
26 return mysql_real_escape_string($s, $this->link
);
29 function query($query, $die_on_error = true) {
30 $result = @mysql_query
($query, $this->link
);
32 $this->last_error
= @mysql_error
($this->link
);
34 @mysql_query
("ROLLBACK", $this->link
);
35 user_error("Query $query failed: " . ($this->link ?
$this->last_error
: "No connection"),
36 $die_on_error ? E_USER_ERROR
: E_USER_WARNING
);
41 function fetch_assoc($result) {
42 return mysql_fetch_assoc($result);
46 function num_rows($result) {
47 return mysql_num_rows($result);
50 function fetch_result($result, $row, $param) {
51 return mysql_result($result, $row, $param);
55 return mysql_close($this->link
);
58 function affected_rows($result) {
59 return mysql_affected_rows($this->link
);
62 function last_error() {
66 function last_query_error() {
67 return $this->last_error
;
71 $this->query("SET time_zone = '+0:0'");
73 if (defined('MYSQL_CHARSET') && MYSQL_CHARSET
) {
74 $this->query("SET NAMES " . MYSQL_CHARSET
);