-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.php
31 lines (28 loc) · 985 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
<?php
require_once 'config.php';
class database {
private $host = DB_HOST;
private $user = DB_USER;
private $pass = DB_PASS;
private $dbname = DB_NAME;
private $charset = 'utf8';
private $con;
public function connect() {
try{
$this->dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname;
$this->options = array (
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::ATTR_EMULATE_PREPARES => false,
);
$this->con = new PDO($this->dsn, $this->user, $this->pass, $this->options);
}catch(PDOException $e) {
echo "error" . $e->getMessage();
}
return $this->con;
}
public function close(){
$this->con = null;
}
}
?>