-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbConnect.php
More file actions
42 lines (32 loc) · 718 Bytes
/
Copy pathDbConnect.php
File metadata and controls
42 lines (32 loc) · 718 Bytes
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
<?php
/**
* Class DbConnect
*/
class DbConnect
{
/**
* @var PDO
*/
private $conn;
function __construct()
{
}
/**
* Establishing database connection
* @return database connection handler
*/
function connect()
{
include_once dirname(__FILE__) . '/db.php';
// Connecting to mysql database
$this->conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Check for database connection error
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit;
}
// returing connection resource
return $this->conn;
}
}
?>