-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.php
More file actions
35 lines (30 loc) · 871 Bytes
/
Copy pathdatabase.php
File metadata and controls
35 lines (30 loc) · 871 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
<?php
/**
* database.php
*
* Provides connector class for database dependency injection
*
* @author BP (3komma3volt)
* @license MIT License
*/
require_once ('configuration.php');
class Database {
private $pdo;
public function __construct() {
try {
$host = DATABASE_HOST;
$dbname = DATABASE_NAME;
$username = DATABASE_USERNAME;
$password = DATABASE_PASSWORD;
$this->pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
error_log('Error connecting to database: ' . $e->getMessage());
throw new PDOException('Error connecting to database');
}
}
public function getConnection() {
return $this->pdo;
}
}
?>