summaryrefslogtreecommitdiff
path: root/common.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-05-07 12:48:07 -0400
committerEvan Prodromou <evan@prodromou.name>2008-05-07 12:48:07 -0400
commitc47de27c114c9998acc01fd2c6df185cd271ec2f (patch)
treea3d42ce54a069bdd364ec34be22b7f8f39f33f4d /common.php
parentd0e8a3b9ab2442d812ec897d90612d9833beee26 (diff)
beginnings of PHP
darcs-hash:20080507164807-84dde-ef7d205a0fedca42064a337786d2f203cdcc5a45.gz
Diffstat (limited to 'common.php')
-rw-r--r--common.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/common.php b/common.php
new file mode 100644
index 000000000..499eafe47
--- /dev/null
+++ b/common.php
@@ -0,0 +1,44 @@
+<?php
+
+# global configuration object
+
+// default configuration, overwritten in config.php
+
+$config =
+ array('site' =>
+ array('name' => 'Just another µB'),
+ 'dsn' =>
+ array('phptype' => 'mysql',
+ 'username' => 'stoica',
+ 'password' => 'apasswd',
+ 'hostspec' => 'localhost',
+ 'database' => 'thedb')
+ 'dboptions' =>
+ array('debug' => 2,
+ 'portability' => DB_PORTABILITY_ALL));
+
+require_once(INSTALLDIR . '/config.php');
+require_once('DB.php');
+
+function common_database() {
+ global $config;
+ $db =& DB::connect($config['dsn'], $config['dboptions']);
+ if (PEAR::isError($db)) {
+ common_server_error($db->getMessage());
+ } else {
+ return $db;
+ }
+}
+
+function common_read_database() {
+ // XXX: read from slave server
+ return common_database();
+}
+
+function common_server_error($msg) {
+ header('Status: 500 Server Error');
+ header('Content-type: text/plain');
+
+ print $msg;
+ exit();
+}