-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sql.php
37 lines (26 loc) · 952 Bytes
/
Sql.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
36
37
<?php
class Sql extends PDO {
private $conn;
public function __construct() {
$this->conn = new PDO("mysql:host=localhost;dbname=dbphp7", "root", "root");
}
private function setParams($statement, $parameters = array()) {
foreach ($parameters as $key => $value) {
$statement->setParam($key, $value);
}
}
private function setParam($statement, $key, $value) {
$statement->bindParam($key, $value);
}
public function query($rawQuery, $params = array()) {
$stmt = $this->conn->prepare($rawQuery);
$this->setParams($stmt, $params);
$stmt->execute();
return $stmt;
}
public function select($rawQuery, $params = array()):array {
$stmt = $this->query($rawQuery, $params);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
?>