-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect.php
51 lines (48 loc) · 1.18 KB
/
connect.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
<?php
/*
* Mysql database class - only one connection allowed
*/
if($_SERVER['SERVER_ADDR'] == 'vxtm.nl'){
$username = 'u36244p31547_interact';
$host = 'vxtm.nl';
$passwort = '12345';
}else{
$username = 'root';
$host = '127.0.0.1';
$passwort = 'root';
}
class Database {
private $_connection;
private static $_instance; //The single instance
private $_host = $host;
private $_username = "root";
private $_password = "root";
private $_database = 'interact';
/*
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() {
$this->_connection = new mysqli($this->_host, $this->_username,
$this->_password, $this->_database);
// Error handling
if(mysqli_connect_error()) {
trigger_error("Failed to conencto to MySQL: " . mysql_connect_error(),
E_USER_ERROR);
}
}
// Magic method clone is empty to prevent duplication of connection
private function __clone() { }
// Get mysqli connection
public function getConnection() {
return $this->_connection;
}
}
?>