|
@@ -15,25 +15,25 @@
|
15
|
15
|
* Insert() *
|
16
|
16
|
* Update() *
|
17
|
17
|
*******************************************************************************/
|
|
18
|
+
|
|
19
|
+include(dirname(__DIR__)."../../DbIds.php");
|
|
20
|
+
|
18
|
21
|
class Connector {
|
19
|
22
|
|
20
|
23
|
private $bdd;
|
21
|
24
|
|
22
|
25
|
function __construct() {
|
23
|
|
- // TODO : Select params to use
|
24
|
|
- $dbconnect = array();
|
25
|
|
- for($i = 0; $i < sizeof($matches[0]); $i++) {
|
26
|
|
- $dbconnect[$matches[1][$i]] = $matches[2][$i];
|
27
|
|
- }
|
|
26
|
+ $dbconnect = getParams();
|
28
|
27
|
|
29
|
28
|
$options = array(
|
30
|
|
- PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
|
|
29
|
+ PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
|
31
|
30
|
);
|
32
|
31
|
|
33
|
|
- $this->bdd = new PDO("mysql:host=".$dbconnect["host"].";dbname="
|
34
|
|
- .$dbconnect["dbname"], $dbconnect["user"], $dbconnect["pass"],
|
35
|
|
- $options);
|
|
32
|
+ $this->bdd = new PDO("mysql:host=".$dbconnect[0].";dbname=".$dbconnect[1],
|
|
33
|
+ $dbconnect[2], $dbconnect[3], $options);
|
|
34
|
+
|
36
|
35
|
$this->bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
36
|
+ $this->bdd->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
37
|
37
|
}
|
38
|
38
|
|
39
|
39
|
function Select($fields, $tables, $options = array()) {
|
|
@@ -44,7 +44,7 @@ class Connector {
|
44
|
44
|
$whereClause = " $upName ";
|
45
|
45
|
foreach($value as $array) {
|
46
|
46
|
if(sizeof($array) != 3 && sizeof($array) != 4) {
|
47
|
|
- throw new Exception('wrong_arg_nmbr_where');
|
|
47
|
+ throw new Exception("wrong_arg_nmbr_where");
|
48
|
48
|
}
|
49
|
49
|
if(sizeof($array) == 3) {
|
50
|
50
|
$whereClause .= $array[0]." ".$array[1]." ? AND ";
|
|
@@ -57,10 +57,10 @@ class Connector {
|
57
|
57
|
$request .= substr($whereClause, 0, -5);
|
58
|
58
|
} else if(($upName = strtoupper($name)) == "ORDER BY") {
|
59
|
59
|
if(sizeof($value) != 2 && substr($value[0], -2) != "()") {
|
60
|
|
- throw new Exception('wrong_arg_nmbr_order_by');
|
|
60
|
+ throw new Exception("wrong_arg_nmbr_order_by");
|
61
|
61
|
}
|
62
|
62
|
|
63
|
|
- $request .= " ".$upName." ".implode(' ', $value);
|
|
63
|
+ $request .= " ".$upName." ".implode(" ", $value);
|
64
|
64
|
} else if(($upName = strtoupper($name)) == "LIMIT") {
|
65
|
65
|
if(sizeof($value) == 1) {
|
66
|
66
|
// La colonne "limit" ne contient qu'un nombre de champs
|
|
@@ -70,10 +70,10 @@ class Connector {
|
70
|
70
|
// nombre de champs
|
71
|
71
|
$request .= " $upName ".$value[0].",".$value[1];
|
72
|
72
|
} else {
|
73
|
|
- throw new Exception('wrong_arg_numbr_limit');
|
|
73
|
+ throw new Exception("wrong_arg_numbr_limit");
|
74
|
74
|
}
|
75
|
75
|
} else {
|
76
|
|
- throw new Exception('unknown_arg');
|
|
76
|
+ throw new Exception("unknown_arg");
|
77
|
77
|
}
|
78
|
78
|
}
|
79
|
79
|
|
|
@@ -106,12 +106,26 @@ class Connector {
|
106
|
106
|
function Update($table, $update) {
|
107
|
107
|
$request = "UPDATE $table SET ";
|
108
|
108
|
$arrayVerif = array();
|
109
|
|
- foreach($update['set'] as $name=>$value) {
|
|
109
|
+ foreach($update["set"] as $name=>$value) {
|
110
|
110
|
$request .= $name."=?,";
|
111
|
111
|
array_push($arrayVerif, $value);
|
112
|
112
|
}
|
113
|
113
|
$request = substr($request, 0, -1)." WHERE ";
|
114
|
|
- foreach($update['where'] as $value) {
|
|
114
|
+ foreach($update["where"] as $value) {
|
|
115
|
+ $request .= $value[0].$value[1]."? AND ";
|
|
116
|
+ array_push($arrayVerif, $value[2]);
|
|
117
|
+ }
|
|
118
|
+ $request = substr($request, 0, -5);
|
|
119
|
+
|
|
120
|
+ $stmt = $this->bdd->prepare($request);
|
|
121
|
+ $stmt->execute($arrayVerif);
|
|
122
|
+ }
|
|
123
|
+
|
|
124
|
+ function Delete($table, $where = array()) {
|
|
125
|
+ $request = "DELETE FROM $table";
|
|
126
|
+ $arrayVerif = array();
|
|
127
|
+ $request .= " WHERE ";
|
|
128
|
+ foreach($where as $value) {
|
115
|
129
|
$request .= $value[0].$value[1]."? AND ";
|
116
|
130
|
array_push($arrayVerif, $value[2]);
|
117
|
131
|
}
|