forked from PlatinumTeam/MBWebchat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.php
90 lines (79 loc) · 2.73 KB
/
db.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
//Catch any errors
if (defined("MBDBRUN"))
return;
define("MBDBRUN", 1);
/**
* Master database control class
*/
class MBDB {
static $databases = null;
/**
* Get the hostname for the specified database
* @param string $db The database's identifier
* @return string The database's hostname
*/
static function getDatabaseHost($db) {
return self::$databases[$db]["host"];
}
/**
* Get the database name for the specified database
* @param string $db The database's identifier
* @return string The database's name
*/
static function getDatabaseName($db) {
return self::$databases[$db]["data"];
}
/**
* Get the username to access the specified database
* @param string $db The database's identifier
* @return string The username to access the database
*/
static function getDatabaseUser($db) {
return self::$databases[$db]["user"];
}
/**
* Get the password to access the specified database
* @param string $db The database's identifier
* @return string The password to access the database
*/
static function getDatabasePass($db) {
return self::$databases[$db]["pass"];
}
/**
* Add a database to the class's list of databases
* @param string $ident The database's identifier
* @param string $host The host for the database
* @param string $data The database name for the database
* @param string $user The username to access the database
* @param string $pass The password to access the database
*/
static function addDatabase($ident = null, $host = null, $data = null, $user = null, $pass = null) {
if ($ident == null || $host == null || $data == null || $user == null || $pass == null)
return;
if (self::$databases == null) {
self::$databases = array();
}
//%b -> resolves to getBranch()
$ident = str_replace("%b", self::getBranch(), $ident);
$host = str_replace("%b", self::getBranch(), $host);
$data = str_replace("%b", self::getBranch(), $data);
$user = str_replace("%b", self::getBranch(), $user);
$pass = str_replace("%b", self::getBranch(), $pass);
self::$databases[$ident] = array("host" => $host, "data" => $data, "user" => $user, "pass" => $pass);
}
/**
* Get the current site "branch" (dev | staging | prod)
* @return string The current branch
*/
static function getBranch() {
$branch = basename(dirname(__DIR__));
return $branch;
}
}
//Default DBs
MBDB::addDatabase("joomla", "localhost", "%b_joomla", "mb-%b", "");
MBDB::addDatabase("platinum", "localhost", "%b_platinum", "mb-%b", "");
MBDB::addDatabase("platinum_old", "localhost", "%b_platinum_old", "mb-%b", "");
MBDB::addDatabase("dedicated", "localhost", "%b_dedicated", "mb-%b", "");
MBDB::addDatabase("fubar", "localhost", "%b_fubar", "mb-%b", "");