-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_globals.php
63 lines (53 loc) · 1.42 KB
/
_globals.php
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
include_once("sparta_config.php");
define('DEBUG', false); // change to true for development
# global functions
function db_connect($rw = 0) {
global $db;
if ($rw == 1) {
// read/write connection (for inserts/updates)
$username = $db['username_rw'];
$password = $db['password_rw'];
} else {
// read-only mode (for reads)
$username = $db['username_ro'];
$password = $db['password_ro'];
}
mysql_connect($db['hostname'],$username,$password);
@mysql_select_db($db['dbname']) or die("Unable to select database");
}
function db_close() {
mysql_close();
}
# useful little function cribbed from http://snipplr.com/view/1358/mysql-fetch-all/
function mysql_fetch_all($result) {
$all = array();
while ($row = mysql_fetch_assoc($result)){ $all[] = $row; }
return $all;
}
function safe_die($msg, $sql='') {
// idea for this helper function from here: http://board.phpbuilder.com/showthread.php?10340977-mysql_query()-or-die()
$details = $msg;
if(!empty($sql)) {
$details .= " ($sql)";
}
$mysql = @mysql_error();
if(!empty($mysql)) {
$details .= ": $mysql";
}
if(DEBUG) {
die($details);
} else {
error_log($details);
die($msg);
}
}
function show404() {
// redirect to 404
global $blog;
$url = $blog['url'] . '/404';
header('Location: '.$url);
exit();
}
# end global functions
?>