]>
git.wh0rd.org - tt-rss.git/blob - classes/db/pdo.php
2 class Db_PDO
implements IDb
{
5 function connect($host, $user, $pass, $db, $port) {
6 $connstr = DB_TYPE
. ":host=$host;dbname=$db;charset=utf8";
9 $this->pdo
= new PDO($connstr, $user, $pass);
10 } catch (PDOException
$e) {
11 die($e->getMessage());
17 function escape_string($s, $strip_tags = true) {
18 if ($strip_tags) $s = strip_tags($s);
20 $qs = $this->pdo
->quote($s);
22 return mb_substr($qs, 1, mb_strlen($qs)-2);
25 function query($query, $die_on_error = true) {
27 return $this->pdo
->query($query);
28 } catch (PDOException
$e) {
29 user_error($e->getMessage(), $die_on_error ? E_USER_ERROR
: E_USER_WARNING
);
33 function fetch_assoc($result) {
36 return $result->fetch();
40 } catch (PDOException
$e) {
41 user_error($e->getMessage(), E_USER_WARNING
);
45 function num_rows($result) {
48 return $result->rowCount();
52 } catch (PDOException
$e) {
53 user_error($e->getMessage(), E_USER_WARNING
);
57 function fetch_result($result, $row, $param) {
58 $line = $this->fetch_assoc($result);
71 function affected_rows($result) {
74 return $result->rowCount();
78 } catch (PDOException
$e) {
79 user_error($e->getMessage(), E_USER_WARNING
);
83 function last_error() {
84 return join(" ", $pdo->errorInfo());