-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslimPDO.php
71 lines (47 loc) · 1.29 KB
/
slimPDO.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/*
slimPDO v1.1
(c) 2017 by Thielicious
Just a small tweaked PDO extension for my own personal use.
*/
namespace Thielicious\utils\slimPDO;
use PDO;
interface slimStruct {
public function prep(string $sql, array $bind = null);
public function qry(string $sql);
}
if (!is_subclass_of("slimPDO","PDO")) {
abstract class slimPDOInit extends PDO {
public function prep(string $sql, array $bind = null) {
$stmt = $this->prepare($sql);
$stmt->execute($bind);
return $stmt;
}
abstract public function qry(string $sql);
}
final class slimPDO extends slimPDOInit implements slimStruct {
public function qry(string $sql) {
return parent::prep($sql);
}
}
}
trait DB {
protected
$pdo;
protected function connect($host, $db, $user, $pass) {
try {
$this->pdo = new slimPDO(
"mysql:host=".$host.";dbname=".$db, $user, $pass,
[
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"
]
);
} catch (PDOException $e) {
exit($e->getMessage());
}
}
}
?>