From 7c181aba6dcf4fdee2cdada09d35aa718d25f431 Mon Sep 17 00:00:00 2001
From: Dries Buytaert
Date: Wed, 31 Oct 2001 20:33:23 +0000
Subject: - Made some improvements/updates to the database abstraction layer.
---
includes/database.inc | 65 +++++----------------------------------------
includes/database.mysql.inc | 56 ++++++++++++++++++++++++++++++++++++++
includes/database.pear.inc | 65 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 127 insertions(+), 59 deletions(-)
create mode 100644 includes/database.mysql.inc
create mode 100644 includes/database.pear.inc
diff --git a/includes/database.inc b/includes/database.inc
index 9621193f1..4022fbc2a 100644
--- a/includes/database.inc
+++ b/includes/database.inc
@@ -1,67 +1,14 @@
getMessage());
-}
-$db_handle->setFetchMode(DB_FETCHMODE_ASSOC);
-
-function db_query($sql, $debug = 0) {
- global $db_handle;
-
- $result = $db_handle->query($sql);
-
- if ($debug) {
- print "query: $sql
"; // error:". $result->getMessage() ."
";
- }
-
- if (DB::isError($result)) {
- watchdog("error", "database: ". $result->getMessage() ."\nquery: ". htmlspecialchars($sql));
- }
-
- return $result;
-}
-
-function db_fetch_object($result) {
- if ($result) {
- return $result->fetchRow(DB_FETCHMODE_OBJECT);
- }
-}
-
-function db_fetch_array($result) {
- if ($result) {
- return $result->fetchRow(DB_FETCHMODE_ASSOC);
- }
-}
-
-function db_num_rows($result) {
- if ($result) {
- return $result->numRows($result);
- }
+if (file_exists("includes/database.$db_type.inc")) {
+ include_once "includes/database.$db_type.inc";
}
-
-function db_result($result, $field = 0) {
- if ($result) {
- $tmp = $result->fetchRow(DB_FETCHMODE_ORDERED);
- return $tmp[$field];
- }
+else {
+ include_once "includes/database.pear.inc";
}
-function db_error($result) {
- global $db_handle;
+db_connect($db_url);
- if (DB::isError($db_handle)) {
- return 1;
- }
-
- return 0;
-}
-
?>
\ No newline at end of file
diff --git a/includes/database.mysql.inc b/includes/database.mysql.inc
new file mode 100644
index 000000000..1b14da5cd
--- /dev/null
+++ b/includes/database.mysql.inc
@@ -0,0 +1,56 @@
+query: $query
error:". mysql_error() ."
";
+ }
+
+ if ($result) {
+ return $result;
+ }
+ else {
+ watchdog("error", "database: ". mysql_error() ."\nquery: ". htmlspecialchars($query));
+ }
+}
+
+function db_fetch_object($result) {
+ if ($result) {
+ return mysql_fetch_object($result);
+ }
+}
+
+function db_fetch_array($result) {
+ if ($result) {
+ return mysql_fetch_array($result, MYSQL_ASSOC);
+ }
+}
+
+function db_num_rows($result) {
+ if ($result) {
+ return mysql_num_rows($result);
+ }
+}
+
+function db_result($result, $row = 0) {
+ if ($result && mysql_num_rows($result) > $row) {
+ return mysql_result($result, $row);
+ }
+}
+
+function db_error() {
+ return mysql_errno();
+}
+
+?>
\ No newline at end of file
diff --git a/includes/database.pear.inc b/includes/database.pear.inc
new file mode 100644
index 000000000..7f3da1a00
--- /dev/null
+++ b/includes/database.pear.inc
@@ -0,0 +1,65 @@
+getMessage());
+ }
+
+ $db_handle->setFetchMode(DB_FETCHMODE_ASSOC);
+}
+
+function db_query($query, $debug = 0) {
+ global $db_handle;
+
+ $result = $db_handle->query($query);
+
+ if ($debug) {
+ print "query: $query
"; // error:". $result->getMessage() ."
";
+ }
+
+ if (DB::isError($result)) {
+ watchdog("error", "database: ". $result->getMessage() ."\nquery: ". htmlspecialchars($query));
+ }
+
+ return $result;
+}
+
+function db_fetch_object($result) {
+ if ($result) {
+ return $result->fetchRow(DB_FETCHMODE_OBJECT);
+ }
+}
+
+function db_fetch_array($result) {
+ if ($result) {
+ return $result->fetchRow(DB_FETCHMODE_ASSOC);
+ }
+}
+
+function db_num_rows($result) {
+ if ($result) {
+ return $result->numRows($result);
+ }
+}
+
+function db_result($result, $row = 0) {
+ if ($result && $result->numRows($result) > $row) {
+ $tmp = $result->fetchRow(DB_FETCHMODE_ORDERED);
+ return $tmp[$row];
+ }
+}
+
+function db_error($result) {
+ global $db_handle;
+
+ return DB::isError($db_handle);
+}
+
+?>
\ No newline at end of file
--
cgit v1.2.3