summaryrefslogtreecommitdiff
path: root/classes/db
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-04-18 08:20:45 +0400
committerAndrew Dolgov <[email protected]>2013-04-18 08:20:45 +0400
commit9ee90455b85350e9f9cd04faf36bad8742141cd9 (patch)
tree50f6f9ea66b40cf8bade86e0b3bdcb77e0ae6978 /classes/db
parent7329ab2dd571f79c69134c6a50d505b18546e103 (diff)
add experimental support for PDO (_ENABLE_PDO)
Diffstat (limited to 'classes/db')
-rw-r--r--classes/db/pdo.php10
-rw-r--r--classes/db/stmt.php32
2 files changed, 34 insertions, 8 deletions
diff --git a/classes/db/pdo.php b/classes/db/pdo.php
index aaac892c6..3020dea88 100644
--- a/classes/db/pdo.php
+++ b/classes/db/pdo.php
@@ -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
index 000000000..4d3596ef1
--- /dev/null
+++ b/classes/db/stmt.php
@@ -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();
+ }
+}
+?>