summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2001-10-09 21:01:47 +0000
committerDries Buytaert <dries@buytaert.net>2001-10-09 21:01:47 +0000
commitf1932821bedfe603eb7a5a7c210e0a7e4c1b4157 (patch)
tree9686b19c30d852f11d5e85f7db104fcf24e22a67 /includes
parent47c6fce5ce33e510fb3a4e51ce7c34db082590c4 (diff)
downloadbrdo-f1932821bedfe603eb7a5a7c210e0a7e4c1b4157.tar.gz
brdo-f1932821bedfe603eb7a5a7c210e0a7e4c1b4157.tar.bz2
- PEAR-ification of Drupal by claw: you can now host Drupal on a wide
range of databases including MySQL, PostgreSQL, MSSQL, and others. For additional information and an 'how to upgrade', check the mails sent to the mailing list.
Diffstat (limited to 'includes')
-rw-r--r--includes/comment.inc12
-rw-r--r--includes/common.inc2
-rw-r--r--includes/conf.php7
-rw-r--r--includes/database.inc69
-rw-r--r--includes/module.inc6
-rw-r--r--includes/node.inc60
-rw-r--r--includes/theme.inc7
7 files changed, 101 insertions, 62 deletions
diff --git a/includes/comment.inc b/includes/comment.inc
index fb1b48e79..4f4531e14 100644
--- a/includes/comment.inc
+++ b/includes/comment.inc
@@ -78,7 +78,7 @@ function comment_reply($pid, $id) {
global $theme;
if ($pid) {
- $item = db_fetch_object(db_query("SELECT c.*, u.uid, u.name FROM comments c LEFT JOIN user u ON c.author = u.uid WHERE c.cid = '$pid'"));
+ $item = db_fetch_object(db_query("SELECT c.*, u.uid, u.name FROM comments c LEFT JOIN users u ON c.author = u.uid WHERE c.cid = '$pid'"));
comment_view(new Comment($item->uid, $item->name, $item->subject, $item->comment, $item->timestamp, $item->url, $item->cid, $item->lid), t("reply to this comment"));
}
else {
@@ -150,7 +150,7 @@ function comment_moderation($comment) {
$options .= " <option value=\"$key\"". ($moderate->score == $key ? " selected=\"selected\"" : "") .">$value</option>\n";
}
- $output .= "<select name=\"moderate[comment][$comment->cid]\">$options</select><br />". ($comment->score ? $comment->score : "--") ." / $comment->votes";
+ $output .= "<select name=\"moderate[comment][$comment->cid]\">$options</select><br />". ($comment->score ? $comment->score : "--") ." / $comment->votes";
return $output;
}
@@ -176,7 +176,7 @@ function comment_order($order) {
function comment_query($lid, $order, $pid = -1) {
- $query .= "SELECT u.*, c.*, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN user u ON c.author = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.lid = '$lid'";
+ $query .= "SELECT u.*, c.*, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN users u ON c.author = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.lid = '$lid'";
if ($pid >= 0) {
$query .= " AND pid = '$pid'";
@@ -235,7 +235,7 @@ function comment_view($comment, $folded = 0) {
function comment_thread_min($cid, $threshold) {
global $user;
- $result = db_query("SELECT u.*, c.*, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN user u ON c.author = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.pid = '$cid' GROUP BY c.cid ORDER BY c.timestamp, c.cid");
+ $result = db_query("SELECT u.*, c.*, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN users u ON c.author = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.pid = '$cid' GROUP BY c.cid ORDER BY c.timestamp, c.cid");
while ($comment = db_fetch_object($result)) {
print "<ul>";
@@ -257,7 +257,7 @@ function comment_thread_max($cid, $mode, $threshold, $level = 0, $dummy = 0) {
** in terms of speed and size.
*/
- $result = db_query("SELECT u.*, c.*, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN user u ON c.author = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.pid = '$cid' GROUP BY c.cid ORDER BY c.timestamp, c.cid");
+ $result = db_query("SELECT u.*, c.*, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN users u ON c.author = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.pid = '$cid' GROUP BY c.cid ORDER BY c.timestamp, c.cid");
while ($comment = db_fetch_object($result)) {
print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td width=\"". ($level * 25) ."\">&nbsp;</td><td>\n";
@@ -307,7 +307,7 @@ function comment_render($lid, $cid) {
$theme->box(t("Control panel"), $theme->comment_controls($threshold, $mode, $order));
if ($cid > 0) {
- $result = db_query("SELECT u.*, c.*, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN user u ON c.author = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.cid = '$cid' GROUP BY c.cid");
+ $result = db_query("SELECT u.*, c.*, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM comments c LEFT JOIN users u ON c.author = u.uid LEFT JOIN moderate m ON c.cid = m.cid WHERE c.cid = '$cid' GROUP BY c.cid");
if ($comment = db_fetch_object($result)) {
comment_view($comment, comment_links($comment));
}
diff --git a/includes/common.inc b/includes/common.inc
index 822ac0a1b..594140a54 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -34,7 +34,7 @@ function error_handler($errno, $message, $filename, $line, $variables) {
function watchdog($type, $message) {
global $user;
- db_query("INSERT INTO watchdog (user, type, message, location, hostname, timestamp) VALUES ('$user->uid', '". check_input($type) ."', '". check_input($message) ."', '". check_input(getenv("REQUEST_URI")) ."', '". check_input(getenv("REMOTE_ADDR")) ."', '". time() ."')");
+ db_query("INSERT INTO watchdog (userid, type, message, location, hostname, timestamp) VALUES ('$user->uid', '". check_input($type) ."', '". check_input($message) ."', '". check_input(getenv("REQUEST_URI")) ."', '". check_input(getenv("REMOTE_ADDR")) ."', '". time() ."')");
}
function throttle($type, $rate) {
diff --git a/includes/conf.php b/includes/conf.php
index a0443d75a..7a89970c2 100644
--- a/includes/conf.php
+++ b/includes/conf.php
@@ -3,10 +3,9 @@
#
# Database settings:
#
-$db_host = "localhost";
-$db_user = "drop"; // username
-$db_pass = "drop"; // password
-$db_name = "database"; // database
+
+# $db_url = "pgsql://userer:password@hostname/database";
+# $db_url = "mysql://userer:password@hostname/database";
#
# Themes:
diff --git a/includes/database.inc b/includes/database.inc
index 8aa5787fa..be3bdbf17 100644
--- a/includes/database.inc
+++ b/includes/database.inc
@@ -1,44 +1,63 @@
<?php
-function db_connect($host, $user, $pass, $name) {
- mysql_pconnect($host, $user, $pass) or die(mysql_error());
- mysql_select_db($name) or die ("unable to select database");
- // NOTE: we are using a persistent connection!
-}
+require_once 'DB.php';
+/*
+** Setup a database connection:
+*/
-function db_query($query, $debug = 0) {
- $result = mysql_query($query);
- if ($debug) print "<P>query: $query<BR>error:". mysql_error() ."</P>";
- if ($result) return $result;
- else watchdog("error", "database: ". mysql_error() ."\nquery: ". htmlspecialchars($query));
+$db_handle = DB::connect($db_url);
+if (DB::isError($db_handle)) {
+ die ("Database problem: ". $db_handle->getMessage());
}
+$db_handle->setFetchMode(DB_FETCHMODE_ASSOC);
-function db_fetch_object($qid) {
- if ($qid) return mysql_fetch_object($qid);
-}
+function db_query($sql, $debug = 0) {
+ global $db_handle;
-function db_num_rows($qid) {
- if ($qid) return mysql_num_rows($qid);
+ $result = $db_handle->query($sql);
+ if (DB::isError($result)) {
+ //if ($debug) {
+ print "<p>query: $sql<br />error:". $result->getMessage() ."</p>";
+ //}
+ watchdog("error", "database: ". $result->getMessage() ."\nquery: ". htmlspecialchars($sql));
+ }
+ return $result;
}
-function db_fetch_row($qid) {
- if ($qid) return mysql_fetch_row($qid);
+function db_fetch_object($result) {
+ if ($result) {
+ return $result->fetchRow(DB_FETCHMODE_OBJECT);
+ }
}
-function db_fetch_array($qid) {
- if ($qid) return mysql_fetch_array($qid, MYSQL_ASSOC);
+function db_fetch_array($result) {
+ if ($result) {
+ return $result->fetchRow(DB_FETCHMODE_ASSOC);
+ }
}
-function db_result($qid, $field = 0) {
- if ($qid) return mysql_result($qid, $field);
+function db_num_rows($result) {
+ if ($result) {
+ return $result->numRows($result);
+ }
}
-function db_insert_id() {
- return mysql_insert_id();
+function db_result($result, $field = 0) {
+ if ($result) {
+ $tmp = $result->fetchRow(DB_FETCHMODE_ASSOC);
+ return $tmp[$field];
+ }
}
-// Setup database connection:
-db_connect($db_host, $db_user, $db_pass, $db_name);
+function db_error($result) {
+ global $db_handle;
+
+ if (DB::isError($db_handle)) {
+ return 1;
+ }
+
+ return 0;
+}
?> \ No newline at end of file
diff --git a/includes/module.inc b/includes/module.inc
index 651c2e404..4b6959c34 100644
--- a/includes/module.inc
+++ b/includes/module.inc
@@ -59,10 +59,10 @@ function module_rehash_blocks($name) {
$block[$item] = addslashes($data);
}
if (!db_fetch_object(db_query("SELECT * FROM blocks WHERE module = '$name' AND name = '$block[info]'"))) {
- db_query("INSERT INTO blocks (name, module, offset) VALUES ('$block[info]', '$name', '$offset')");
+ db_query("INSERT INTO blocks (name, module, delta) VALUES ('$block[info]', '$name', '$offset')");
}
else {
- db_query("UPDATE blocks SET offset = '$offset', remove = '0' WHERE module = '$name' AND name = '$block[info]'");
+ db_query("UPDATE blocks SET delta = '$offset', remove = '0' WHERE module = '$name' AND name = '$block[info]'");
}
}
}
@@ -88,4 +88,4 @@ function module_rehash($name) {
}
}
-?> \ No newline at end of file
+?>
diff --git a/includes/node.inc b/includes/node.inc
index 67c8a51f0..747c8d8b4 100644
--- a/includes/node.inc
+++ b/includes/node.inc
@@ -18,7 +18,19 @@ function _node_get($conditions) {
}
if ($type) {
- return db_query("SELECT n.*, l.*, u.uid, u.name, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM node n LEFT JOIN $type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN user u ON n.author = u.uid LEFT JOIN moderate m ON m.nid = n.nid WHERE $where GROUP BY n.nid ORDER BY n.timestamp DESC");
+ $result = db_query("SELECT n.*, l.*, u.uid, u.name FROM node n LEFT JOIN $type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.uid WHERE $where ORDER BY n.timestamp DESC");
+
+/*
+ db_query ("BEGIN");
+ db_query ("CREATE TEMPORARY TABLE modhole AS SELECT n.nid, SUM(m.score) / COUNT(m.cid) AS score, COUNT(m.cid) AS votes FROM node n LEFT JOIN $type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.uid LEFT JOIN moderate m ON m.nid = n.nid WHERE $where GROUP BY n.nid");
+ $result = db_query ("SELECT n.*, l.*, u.uid, u.name, m.score AS score, m.votes AS votes FROM node n INNER JOIN modhole m ON m.nid = n.nid LEFT JOIN $type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.uid WHERE $where ORDER BY n.timestamp DESC");
+ db_query("DROP TABLE modhole");
+ db_query("COMMIT");
+
+ 'score' isn't in GROUP BY
+*/
+
+ return $result;
}
}
@@ -64,6 +76,8 @@ function node_get_comments($nid) {
}
function node_save($node, $filter) {
+ global $db_handle;
+
$rows = array(nid, lid, cid, tid, type, title, score, votes, author, status, comment, promote, moderate, attributes, timestamp, timestamp_posted, timestamp_queued, timestamp_hidden);
if ($node[nid] > 0) {
@@ -118,26 +132,34 @@ function node_save($node, $filter) {
$f2 = implode(", ", $f2);
$v2 = implode(", ", $v2);
- // insert data, try to roll-back when something goes wrong:
- $result = db_query("INSERT INTO node ($f1) VALUES ($v1)");
- if ($result && $nid = db_insert_id()) {
- $result = db_query("INSERT INTO $filter[type] ($f2, nid) VALUES ($v2, $nid)");
- if ($result && $lid = db_insert_id()) {
- $result = db_query("UPDATE node SET lid = '$lid' WHERE nid = '$nid'");
- if ($result) {
- watchdog("special", "node: added $filter[type] '$node[title]'");
+
+ $result = db_query ("BEGIN");
+ if (db_error ($result)) {
+ watchdog ("error", "database: ". $result->getMessage () ."\nquery: ". htmlspecialchars ("BEGIN"));
+ }
+ else {
+
+ $nid = $db_handle->nextId ("node_nid");
+ $lid = $db_handle->nextId ($filter[type] . "_lid");
+
+ $result = db_query ("INSERT INTO node ($f1, nid, lid) VALUES ($v1, '$nid', '$lid')");
+ if (db_error ($result)) {
+ watchdog("warning", "node: added $filter[type] '$node[title]' - failed");
+ }
+ else {
+ $result = db_query ("INSERT INTO $filter[type] ($f2, nid, lid) VALUES ($v2, '$nid', '$lid')");
+ if (db_error ($result)) {
+ watchdog("warning", "node: added $filter[type] '$node[title]' - failed");
}
else {
- watchdog("warning", "node: added $filter[type] '$node[title]' - failed");
+ $result = db_query ("COMMIT");
+ if (db_error ($result)) {
+ watchdog ("error", "database: ". $result->getMessage () ."\nquery: ". htmlspecialchars ("BEGIN"));
+ $db_handle->rollback ();
+ }
+ watchdog("special", "node: added $filter[type] '$node[title]'");
}
}
- else {
- db_query("DELETE FROM node WHERE nid = '$nid'");
- watchdog("warning", "node: added $filter[type] '$node[title]' - failed");
- }
- }
- else {
- watchdog("warning", "node: added $filter[type] '$node[title]' - failed");
}
}
@@ -163,9 +185,7 @@ function node_form($node) {
}
function node_status($value) {
-
$status = array("dumped", "expired", "queued", "posted");
-
if (module_exist($value)) {
return array_intersect($status, node_invoke($value, "status"));
}
@@ -278,4 +298,4 @@ function node_moderation($nid) {
return $output;
}
-?> \ No newline at end of file
+?>
diff --git a/includes/theme.inc b/includes/theme.inc
index 345275617..a4d0eb2a6 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -96,12 +96,13 @@ function theme_blocks($region, $theme) {
}
break;
case "/index.php":
- if ($user->uid) $result = db_query("SELECT * FROM blocks b LEFT JOIN layout l ON b.name = l.block WHERE (b.status = 2 OR (b.status = 1 AND l.user = '$user->uid'))". (($region == "left" || $region == "right") ? ($region == "left" ? " AND b.region = 0" : " AND b.region = 1") : "") ." ORDER BY weight");
+
+ if ($user->uid) $result = db_query("SELECT * FROM blocks b LEFT JOIN layout l ON b.name = l.block WHERE (b.status = 2 OR (b.status = 1 AND l.userid = '$user->uid'))". (($region == "left" || $region == "right") ? ($region == "left" ? " AND b.region = 0" : " AND b.region = 1") : "") ." ORDER BY weight");
else $result = db_query("SELECT * FROM blocks WHERE status = 2". (($region == "left" || $region == "right") ? ($region == "left" ? " AND region = 0" : " AND region = 1") : "") ." ORDER BY weight");
- while ($block = db_fetch_object($result)) {
+ while ($result && ($block = db_fetch_object($result))) {
$blocks = module_invoke($block->module, "block");
if ($blocks[$block->offset]["content"])
- $theme->box(t($blocks[$block->offset]["subject"]), $blocks[$block->offset]["content"], $region);
+ $theme->box(t($blocks[$block->delta]["subject"]), $blocks[$block->delta]["content"], $region);
}
break;
}