summaryrefslogtreecommitdiff
path: root/common.php
blob: 499eafe4797ddf3df20755f553e0d82bae897289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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();
}