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 new Db_Stmt($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 return $result->fetch_result($row, $param);
65 function affected_rows($result) {
68 return $result->rowCount();
72 } catch (PDOException $e) {
73 user_error($e->getMessage(), E_USER_WARNING);
77 function last_error() {
78 return join(" ", $pdo->errorInfo());