diff options
author | Andrew Dolgov <[email protected]> | 2017-11-30 10:47:42 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2017-11-30 10:47:42 +0300 |
commit | 99bda9cc12cd39907adc6b76dc3bee4e9241b52b (patch) | |
tree | 608ed80517441e89de5d79a0f606d7a9a5722799 /classes/db | |
parent | 1a4ff852def7f70d99a3ee330b405dd0ff3fe470 (diff) |
add some starting pdo glue
Diffstat (limited to 'classes/db')
-rw-r--r-- | classes/db/pdo.php | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/classes/db/pdo.php b/classes/db/pdo.php deleted file mode 100644 index d3070fac4..000000000 --- a/classes/db/pdo.php +++ /dev/null @@ -1,100 +0,0 @@ -<?php -class Db_PDO implements IDb { - private $pdo; - - function connect($host, $user, $pass, $db, $port) { - $connstr = DB_TYPE . ":host=$host;dbname=$db"; - - if (DB_TYPE == "mysql") $connstr .= ";charset=utf8"; - - try { - $this->pdo = new PDO($connstr, $user, $pass); - $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $this->init(); - } 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)); - } 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); - } - - 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(" ", $this->pdo->errorInfo()); - } - - function init() { - switch (DB_TYPE) { - case "pgsql": - $this->query("set client_encoding = 'UTF-8'"); - $this->query("set datestyle = 'ISO, european'"); - $this->query("set TIME ZONE 0"); - return; - case "mysql": - $this->query("SET time_zone = '+0:0'"); - return; - } - - return true; - } - -}
\ No newline at end of file |