You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tt-rss/classes/db/pdo.php

82 lines
1.5 KiB
PHTML

11 years ago
<?php
class Db_PDO implements IDb {
private $pdo;
function connect($host, $user, $pass, $db, $port) {
$connstr = DB_TYPE . ":host=$host;dbname=$db;charset=utf8";
try {
$this->pdo = new PDO($connstr, $user, $pass);
} catch (PDOException $e) {
die($e->getMessage());
}
return $this->pdo;
}
function escape_string($s, $strip_tags = true) {
if ($strip_tags) $s = strip_tags($s);
$qs = $this->pdo->quote($s);
return mb_substr($qs, 1, mb_strlen($qs)-2);
}
function query($query, $die_on_error = true) {
try {
return new Db_Stmt($this->pdo->query($query));
11 years ago
} catch (PDOException $e) {
user_error($e->getMessage(), $die_on_error ? E_USER_ERROR : E_USER_WARNING);
}
}
function fetch_assoc($result) {
try {
if ($result) {
return $result->fetch();
} else {
return null;
}
} catch (PDOException $e) {
user_error($e->getMessage(), E_USER_WARNING);
}
}
function num_rows($result) {
try {
if ($result) {
return $result->rowCount();
} else {
return false;
}
} catch (PDOException $e) {
user_error($e->getMessage(), E_USER_WARNING);
}
}
function fetch_result($result, $row, $param) {
return $result->fetch_result($row, $param);
11 years ago
}
function close() {
$this->pdo = null;
}
function affected_rows($result) {
try {
if ($result) {
return $result->rowCount();
} else {
return null;
}
} catch (PDOException $e) {
user_error($e->getMessage(), E_USER_WARNING);
}
}
function last_error() {
return join(" ", $pdo->errorInfo());
}
}
?>