-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.php
35 lines (33 loc) · 868 Bytes
/
database.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
<?php
require_once ("config.php");
class MySQLDatabase {
private $connection;
public $stmt;
function __construct() {
$this->connection = new mysqli ( DB_SERVER, DB_USER, DB_PASS, DB_NAME );
if (mysqli_connect_errno ()) {
die ( "Database Connection Failed: " . mysqli_connect_error () );
}
}
function __destruct() {
$this->connection->close ();
}
public function query($sql) {
$result = $this->connection->query ( $sql );
if (! $result) {
die ( "MySQL Query Failed: " . $this->connection->error );
}
return $result;
}
public function prepare_statement($sql) {
$this->stmt = $this->connection->prepare ( $sql );
}
public function execute_statement() {
return $this->stmt->execute ();
}
public function mysqli_error() {
return $this->connection->error;
}
}
$database = new MySQLDatabase ();
?>