-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path202-config-sample.php
executable file
·62 lines (51 loc) · 1.9 KB
/
202-config-sample.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
<?php
// ** MySQL settings** //
$dbname = 'putyourdbnamehere'; // The name of the database
$dbuser = 'usernamehere'; // Your MySQL username
$dbpass = 'yourpasswordhere'; // ...and password
$dbhost = 'localhost'; // 99% chance you won't need to change this value
$dbhostro = 'localhost'; // Only change this to use a read replica for reading data
$mchost = 'localhost'; // this is the memcache server host, if you don't know what this is, don't touch it.
/*---DONT EDIT ANYTHING BELOW THIS LINE!---*/
//Database conncetion class
class DB {
private $_connection,$_connectionro;
private static $_instance; //The single instance
/*
Get an instance of the Database
@return Instance
*/
public static function getInstance() {
if(!self::$_instance) { // If no instance then make one
self::$_instance = new self();
}
return self::$_instance;
}
// Constructor
private function __construct() {
global $dbhost,$dbhostro;
global $dbuser;
global $dbpass;
global $dbname;
$this->_connection = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
$this->_connectionro = new mysqli($dbhostro, $dbuser, $dbpass, $dbname);
}
// Magic method clone is empty to prevent duplication of connection
private function __clone() { }
// Get mysqli connection
public function getConnection() {
return $this->_connection;
}
// Get mysqli ro connection
public function getConnectionro() {
return $this->_connectionro;
}
}
try {
$database = DB::getInstance();
$db = $database->getConnection();
$dbro = $database->getConnectionro();
} catch (Exception $e) {
$db = false;
$dbro = false;
}