|
@@ -36,6 +36,13 @@ class Connector {
|
36
|
36
|
$this->bdd->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
37
|
37
|
}
|
38
|
38
|
|
|
39
|
+ /**
|
|
40
|
+ * @param string $fields Fields to select
|
|
41
|
+ * @param string $tables Tables to select from
|
|
42
|
+ * @param mixed[] $options Array filled with the selection options, such as "WHERE", "ORDER BY" and "LIMIT"
|
|
43
|
+ * @return mixed[]|null Array of values if the request went OK, NULL else
|
|
44
|
+ * @throws InvalidArgumentException There was an error within the arguments array
|
|
45
|
+ */
|
39
|
46
|
function Select($fields, $tables, $options = array()) {
|
40
|
47
|
$request = "SELECT $fields FROM $tables ";
|
41
|
48
|
$arrayVerif = array();
|
|
@@ -44,7 +51,7 @@ class Connector {
|
44
|
51
|
$whereClause = " $upName ";
|
45
|
52
|
foreach($value as $array) {
|
46
|
53
|
if(sizeof($array) != 3 && sizeof($array) != 4) {
|
47
|
|
- throw new Exception("wrong_arg_nmbr_where");
|
|
54
|
+ throw new InvalidArgumentException("wrong_arg_nmbr_where");
|
48
|
55
|
}
|
49
|
56
|
if(sizeof($array) == 3) {
|
50
|
57
|
$whereClause .= $array[0]." ".$array[1]." ? AND ";
|
|
@@ -57,7 +64,7 @@ class Connector {
|
57
|
64
|
$request .= substr($whereClause, 0, -5);
|
58
|
65
|
} else if(($upName = strtoupper($name)) == "ORDER BY") {
|
59
|
66
|
if(sizeof($value) != 2 && substr($value[0], -2) != "()") {
|
60
|
|
- throw new Exception("wrong_arg_nmbr_order_by");
|
|
67
|
+ throw new InvalidArgumentException("wrong_arg_nmbr_order_by");
|
61
|
68
|
}
|
62
|
69
|
|
63
|
70
|
$request .= " ".$upName." ".implode(" ", $value);
|
|
@@ -70,10 +77,10 @@ class Connector {
|
70
|
77
|
// nombre de champs
|
71
|
78
|
$request .= " $upName ".$value[0].",".$value[1];
|
72
|
79
|
} else {
|
73
|
|
- throw new Exception("wrong_arg_numbr_limit");
|
|
80
|
+ throw new InvalidArgumentException("wrong_arg_numbr_limit");
|
74
|
81
|
}
|
75
|
82
|
} else {
|
76
|
|
- throw new Exception("unknown_arg");
|
|
83
|
+ throw new InvalidArgumentException("unknown_arg");
|
77
|
84
|
}
|
78
|
85
|
}
|
79
|
86
|
|
|
@@ -86,6 +93,10 @@ class Connector {
|
86
|
93
|
}
|
87
|
94
|
}
|
88
|
95
|
|
|
96
|
+ /**
|
|
97
|
+ * @param string $table Name of the table where the insertion takes place
|
|
98
|
+ * @param string[] $values Array of values to insert in the database
|
|
99
|
+ */
|
89
|
100
|
function Insert($table, $values) {
|
90
|
101
|
$request = "INSERT INTO $table(";
|
91
|
102
|
$valeurs = "VALUES(";
|
|
@@ -103,6 +114,11 @@ class Connector {
|
103
|
114
|
$stmt->execute($arrayVerif);
|
104
|
115
|
}
|
105
|
116
|
|
|
117
|
+ /**
|
|
118
|
+ * @param string $table Name of the table where the update takes place
|
|
119
|
+ * @param mixed[] $update Array of fields to update with new values, with a "set"
|
|
120
|
+ * row filled with values, and a "where" row with conditions
|
|
121
|
+ */
|
106
|
122
|
function Update($table, $update) {
|
107
|
123
|
$request = "UPDATE $table SET ";
|
108
|
124
|
$arrayVerif = array();
|
|
@@ -121,6 +137,10 @@ class Connector {
|
121
|
137
|
$stmt->execute($arrayVerif);
|
122
|
138
|
}
|
123
|
139
|
|
|
140
|
+ /**
|
|
141
|
+ * @param string $table Name of the table where the deletion takes place
|
|
142
|
+ * @param mixed[] $where Array of conditions to select the right row(s) to delete
|
|
143
|
+ */
|
124
|
144
|
function Delete($table, $where = array()) {
|
125
|
145
|
$request = "DELETE FROM $table";
|
126
|
146
|
$arrayVerif = array();
|