-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.php
46 lines (34 loc) · 763 Bytes
/
db.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
<?php
function connect() {
try {
$bdd = new PDO('sqlite:patterns.sqlite');
}
catch(Exception $e) {
die('Erreur : ' . $e->getMessage());
}
return $bdd;
}
function insert($sql, $bdd, $data = false) {
if ($data) {
$req = $bdd->prepare($sql);
$req->execute($data);
} else {
$req = $bdd->exec($sql);
}
if ($req === false) {
echo 'ERREUR : ', print_r($bdd->errorInfo());
} else {
//echo 'Table créée';
}
}
function select($sql, $bdd) {
$req = $bdd->query($sql);
$req = $req->fetch(PDO::FETCH_ASSOC);
return $req;
}
function mselect($sql, $bdd) {
$req = $bdd->query($sql);
$req = $req->fetchAll(PDO::FETCH_ASSOC);
return $req;
}
?>