-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBManager.php
43 lines (38 loc) · 1.52 KB
/
DBManager.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
38
39
40
41
42
43
<?php
class DBManager {
private $dbHost;
private $dbName;
private $dbUser;
private $dbPwd;
private $PDO;
public function __construct(string $dbHost, string $dbName, string $dbUser, string $dbPwd) {
$this->dbHost = $dbHost;
$this->dbName = $dbName;
$this->dbUser = $dbUser;
$this->dbPwd = $dbPwd;
$this->PDO = new PDO("mysql:dbname=$this->dbName;host=$this->dbHost", $this->dbUser, $this->dbPwd);
$this->PDO->query("SET NAMES utf8");
}
public function executeModifierCommand(string $sqlCommand, array $parameters) {
$PDOStmt = $this->PDO->prepare($sqlCommand);
for($i=0;$i<count($parameters);$i++) {
$PDOStmt->bindParam(($i+1), $parameters[$i]);
}
$PDOStmt->execute();
return ($PDOStmt->errorCode() == '00000');
}
public function executeQuery(string $sqlCommand, array $parameters = array(), bool $expectMoreRecord = true) {
if(empty($parameters)) {
$PDOStmt = $this->PDO->query($sqlCommand);
} else {
$PDOStmt = $this->PDO->prepare($sqlCommand);
for($i=0;$i<count($parameters);$i++) {
$PDOStmt->bindParam(($i+1), $parameters[$i]);
}
$PDOStmt->execute();
}
$result = ($expectMoreRecord) ? $PDOStmt->fetchAll() : $PDOStmt->fetch();
return $result;
}
}
?>