]> git.wh0rd.org Git - tt-rss.git/commitdiff
add some starting pdo glue
authorAndrew Dolgov <noreply@fakecake.org>
Thu, 30 Nov 2017 07:47:42 +0000 (10:47 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Thu, 30 Nov 2017 07:47:42 +0000 (10:47 +0300)
classes/db.php
classes/db/pdo.php [deleted file]

index 3b71f3c8f00cae1db65193b16dba13693bea74cb..2244925023bddcee815963344a629328e0717383 100644 (file)
@@ -3,15 +3,13 @@ class Db implements IDb {
        private static $instance;
        private $adapter;
        private $link;
+       private $pdo;
 
        private function __construct() {
 
                $er = error_reporting(E_ALL);
 
-               if (defined('_ENABLE_PDO') && _ENABLE_PDO && class_exists("PDO")) {
-                       $this->adapter = new Db_PDO();
-               } else {
-                       switch (DB_TYPE) {
+               switch (DB_TYPE) {
                        case "mysql":
                                $this->adapter = new Db_Mysqli();
                                break;
@@ -20,7 +18,6 @@ class Db implements IDb {
                                break;
                        default:
                                die("Unknown DB_TYPE: " . DB_TYPE);
-                       }
                }
 
                if (!$this->adapter) {
@@ -28,6 +25,17 @@ class Db implements IDb {
                        exit(100);
                }
 
+               $db_port = defined(DB_PORT) ? ';port='.DB_PORT : '';
+
+               $this->pdo = new PDO(DB_TYPE . ':dbname='.DB_NAME.';host='.DB_HOST.$db_port,
+                       DB_USER,
+                       DB_PASS);
+
+               if (!$this->pdo) {
+                       print("Error connecting via PDO.");
+                       exit(101);
+               }
+
                $this->link = $this->adapter->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, defined('DB_PORT') ? DB_PORT : "");
 
                if (!$this->link) {
diff --git a/classes/db/pdo.php b/classes/db/pdo.php
deleted file mode 100644 (file)
index d3070fa..0000000
+++ /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