summaryrefslogtreecommitdiffstats
path: root/code
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2006-02-11 01:31:03 +0100
committerneoraider <devnull@localhost>2006-02-11 01:31:03 +0100
commit446b94d9cd09003903a270619f368cba0b7ca594 (patch)
tree6fdb044813f4f07d365a05e4dbdb537c6bfdf13c /code
parentaf3aaf3630d4634a85d7d912f751f3bf36633278 (diff)
downloadneon-446b94d9cd09003903a270619f368cba0b7ca594.tar
neon-446b94d9cd09003903a270619f368cba0b7ca594.zip
DB-Funktionen durch Klasse gekapselt.
Diffstat (limited to 'code')
-rw-r--r--code/db.inc.php26
-rw-r--r--code/nav.inc.php2
-rw-r--r--code/pages.inc.php8
-rw-r--r--code/user.inc.php10
4 files changed, 28 insertions, 18 deletions
diff --git a/code/db.inc.php b/code/db.inc.php
index 3f5c444..d46b5cd 100644
--- a/code/db.inc.php
+++ b/code/db.inc.php
@@ -6,16 +6,26 @@
include('adodb.inc.php');
- $conn = ADONewConnection($config['driver']);
- $conn->PConnect($config['server'], $config['user'], $config['password'], $config['db']);
- function DBQuery($query, $args = null) {
- $sql = $GLOBALS['conn']->Prepare($query);
- return $GLOBALS['conn']->Execute($sql, $args);
+ class DB {
+ var $conn;
+
+ function DB($driver, $server, $user, $passwort, $database) {
+ $this->conn = ADONewConnection($driver);
+ $this->conn->PConnect($server, $user, $passwort, $database);
+ }
+
+ function Query($query, $args = null) {
+ $sql = $this->conn->Prepare($query);
+ return $this->conn->Execute($sql, $args);
+ }
+
+ function InsertID() {
+ return $this->conn->Insert_ID();
+ }
}
- function DBInsertID() {
- return $GLOBALS['conn']->Insert_ID();
- }
+ $db = new DB($config['driver'], $config['server'], $config['user'],
+ $config['password'], $config['db']);
}
?>
diff --git a/code/nav.inc.php b/code/nav.inc.php
index 59f4c8d..1a4a5bd 100644
--- a/code/nav.inc.php
+++ b/code/nav.inc.php
@@ -8,7 +8,7 @@
var $entries = array();
function Nav() {
- $res = DBQuery('SELECT * FROM nav ORDER BY id');
+ $res = $GLOBALS['db']->Query('SELECT * FROM nav ORDER BY id');
while(!$res->EOF) {
$this->entries[$res->fields[0]] = new NavEntry($res->fields[1], $res->fields[2], $res->fields[3]);
diff --git a/code/pages.inc.php b/code/pages.inc.php
index 24d0ec4..4516303 100644
--- a/code/pages.inc.php
+++ b/code/pages.inc.php
@@ -12,7 +12,7 @@
return array('title' => $name,
'content' => ErrorMessage('PageNotFound', array('page' => $name)));
- $res = DBQuery('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type));
+ $res = $GLOBALS['db']->Query('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type));
if(!$this->HasAccess($name, $type))
return array('title' => $name,
@@ -32,7 +32,7 @@
return array('title' => $name,
'content' => ErrorMessage('PageNotFound', array('page' => $name)));
- $res = DBQuery('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type));
+ $res = $GLOBALS['db']->Query('SELECT id, handler, data FROM pages WHERE name = ? AND type = ?', array($name, $type));
if(!$GLOBALS['user']->IsAdmin())
return array('title' => $name,
@@ -47,13 +47,13 @@
}
function Exists($name, $type) {
- $res = DBQuery('SELECT id FROM pages WHERE name = ? AND type = ?', array($name, $type));
+ $res = $GLOBALS['db']->Query('SELECT id FROM pages WHERE name = ? AND type = ?', array($name, $type));
return ($res->RecordCount() > 0);
}
function HasAccess($name, $type) {
- $res = DBQuery('SELECT access FROM pages WHERE name = ? AND type = ?', array($name, $type));
+ $res = $GLOBALS['db']->Query('SELECT access FROM pages WHERE name = ? AND type = ?', array($name, $type));
return ($GLOBALS['user']->IsAdmin() || ($res->fields[0] & (1 << $GLOBALS['user']->GetGid())) != 0);
}
diff --git a/code/user.inc.php b/code/user.inc.php
index 4899612..7bd1e99 100644
--- a/code/user.inc.php
+++ b/code/user.inc.php
@@ -10,7 +10,7 @@
function User() {
if($_COOKIE['login']) {
- $res = DBQuery('SELECT id, gid, sid FROM users WHERE id = ? AND sid = ?',
+ $res = $GLOBALS['db']->Query('SELECT id, gid, sid FROM users WHERE id = ? AND sid = ?',
array(substr($_COOKIE['login'], 32),
substr($_COOKIE['login'], 0, 32)));
@@ -24,7 +24,7 @@
}
if($this->uid == 0 && $_GET['login']) {
- $res = DBQuery('SELECT id, gid, sid FROM users WHERE id = ? AND sid = ?',
+ $res = $GLOBALS['db']->Query('SELECT id, gid, sid FROM users WHERE id = ? AND sid = ?',
array(substr($_GET['login'], 32),
substr($_GET['login'], 0, 32)));
@@ -39,13 +39,13 @@
}
function Login($name, $pass) {
- $res = DBQuery('SELECT id, gid FROM users WHERE user = ? AND password = ?', array($name, $pass));
+ $res = $GLOBALS['db']->Query('SELECT id, gid FROM users WHERE user = ? AND password = ?', array($name, $pass));
if($res->RecordCount()) {
$id = $res->fields[0];
$sid = md5(uniqid($name . " * " . $pass . " * " . rand()));
- DBQuery('UPDATE users SET sid = ? WHERE id = ?', array($sid, $id));
+ $GLOBALS['db']->Query('UPDATE users SET sid = ? WHERE id = ?', array($sid, $id));
$this->uid = $id;
$this->gid = $res->fields[1];
@@ -62,7 +62,7 @@
}
function Logout() {
- DBQuery('UPDATE users SET sid = \'\' WHERE id = ?', $this->uid);
+ $GLOBALS['db']->Query('UPDATE users SET sid = \'\' WHERE id = ?', $this->uid);
$this->uid = 0;
$this->gid = 0;