-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.class.php
36 lines (23 loc) · 862 Bytes
/
db.class.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
<?php
class db {
private $host = 'localhost';
private $user = 'root';
private $password = '';
private $database = 'twitter';
protected static $connection;
public function Connect() {
if (!isset(self::$connection)) {
self::$connection = mysqli_connect($this->host, $this->user, $this->password, $this->database);
mysqli_set_charset(self::$connection, 'utf-8');
if (mysqli_connect_errno()) {
echo 'Fail to connect to mysql server: '.mysqli_connect_error();
return false;
}
}
return self::$connection;
}
public function __destruct(){
mysqli_close(self::$connection);
}
}
?>