-
Notifications
You must be signed in to change notification settings - Fork 3
/
DbConnection.php.dist
36 lines (34 loc) · 1.13 KB
/
DbConnection.php.dist
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
<?php
class MySQLiConnectionFactory {
static $SERVERS = array(
array(
'proj' => '',
'host' => 'localhost',
'username' => '',
'password' => '',
'database' => ''
),
array(
'proj' => '',
'host' => 'localhost',
'username' => '',
'password' => '',
'database' => ''
)
);
public static function getCon($proj) {
// Figure out which connections are open, automatically opening any connections
// which are failed or not yet opened but can be (re)established.
for ($i = 0, $n = count(MySQLiConnectionFactory::$SERVERS); $i < $n; $i++) {
$server = MySQLiConnectionFactory::$SERVERS[$i];
if($server['proj'] == $proj){
$connection = new mysqli($server['host'], $server['username'], $server['password'], $server['database']);
if(mysqli_connect_errno()){
//throw new Exception('Could not connect to any databases! Please try again later.');
}
return $connection;
}
}
}
}
?>