]> git.wh0rd.org - tt-rss.git/commitdiff
add experimental support for PDO (_ENABLE_PDO)
authorAndrew Dolgov <fox@fakecake.org>
Thu, 18 Apr 2013 04:20:45 +0000 (08:20 +0400)
committerAndrew Dolgov <fox@fakecake.org>
Thu, 18 Apr 2013 04:20:45 +0000 (08:20 +0400)
classes/db.php
classes/db/pdo.php
classes/db/stmt.php [new file with mode: 0644]

index 86d2ab897d0afa608a5a7f945dfc32a0dfa5a75f..f31a2a9a313f008e0a90f4cc11c2c4b26735d4d3 100644 (file)
@@ -8,7 +8,7 @@ class Db implements IDb {
 
                $er = error_reporting(E_ALL);
 
-               if (class_exists("PDO")) {
+               if (defined('_ENABLE_PDO') && _ENABLE_PDO && class_exists("PDO")) {
                        $this->adapter = new Db_PDO();
                } else {
                        switch (DB_TYPE) {
index aaac892c61cc3662b96b5274492e70fe5eac85a6..3020dea88a0c5d56063e832d0ae1c1d08252646f 100644 (file)
@@ -24,7 +24,7 @@ class Db_PDO implements IDb {
 
        function query($query, $die_on_error = true) {
                try {
-                       return $this->pdo->query($query);
+                       return new Db_Stmt($this->pdo->query($query));
                } catch (PDOException $e) {
                        user_error($e->getMessage(), $die_on_error ? E_USER_ERROR : E_USER_WARNING);
                }
@@ -55,13 +55,7 @@ class Db_PDO implements IDb {
        }
 
        function fetch_result($result, $row, $param) {
-               $line = $this->fetch_assoc($result);
-
-               if ($line)
-                       return $line[$param];
-               else
-                       return null;
-
+               return $result->fetch_result($row, $param);
        }
 
        function close() {
diff --git a/classes/db/stmt.php b/classes/db/stmt.php
new file mode 100644 (file)
index 0000000..4d3596e
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+class Db_Stmt {
+       private $stmt;
+       private $cache;
+
+       function __construct($stmt) {
+               $this->stmt = $stmt;
+               $this->cache = false;
+       }
+
+       function fetch_result($row, $param) {
+               if (!$this->cache) {
+                       $this->cache = $this->stmt->fetchAll();
+               }
+
+               if (isset($this->cache[$row])) {
+                       return $this->cache[$row][$param];
+               } else {
+                       user_error("Unable to jump to row $row", E_USER_WARNING);
+                       return false;
+               }
+       }
+
+       function rowCount() {
+               return $this->stmt->rowCount();
+       }
+
+       function fetch() {
+               return $this->stmt->fetch();
+       }
+}
+?>