$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) {
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);
}
}
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() {
--- /dev/null
+<?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();
+ }
+}
+?>