-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathDB.php
More file actions
22 lines (17 loc) · 684 Bytes
/
Copy pathDB.php
File metadata and controls
22 lines (17 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
class DB {
private $pdo;
public function __construct($host, $dbname, $username, $password) {
$pdo = new PDO('mysql:host='.$host.';dbname='.$dbname.';charset=utf8', $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->pdo = $pdo;
}
public function query($query, $params = array()) {
$statement = $this->pdo->prepare($query);
$statement->execute($params);
if (explode(' ', $query)[0] == 'SELECT') {
$data = $statement->fetchAll();
return $data;
}
}
}