-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbclass.php
More file actions
323 lines (316 loc) · 11.9 KB
/
dbclass.php
File metadata and controls
323 lines (316 loc) · 11.9 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?php
class db{
public $host="localhost";
public $user = "daklay";
public $pass = "daklay123";
public $dbName = "test";
public function connect(){
$dsn = 'mysql:host='.$this->host.';dbname='.$this->dbName;
$pdo = new PDO($dsn, $this->user, $this->pass);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
}
}
// product
class test extends db{
public function getCat(){
$sql = "SELECT DISTINCT categorie FROM products";
$stmt = $this->connect()->query($sql);
$res= $stmt->fetchAll();
return $res;
}
// public function setWhere(){
// $sql = "SELECT FROM products WHERE brand =?";
// }
public function getWhereProducts($categorie){
$sql = "SELECT * FROM products WHERE categorie !='' AND categorie IN(?)"; //the problem is here in IN
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$categorie]);
$res = $stmt->fetchAll();
return $res;
}
public function getWhereProducts2($brand){
$sql = "SELECT * FROM products WHERE brand !='' AND brand IN(?)"; //the problem is here in IN
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$brand]);
$res = $stmt->fetchAll();
return $res;
}
public function getWhereProductprice($price){
$sql = "SELECT * FROM products WHERE price !='' AND price > ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$price]);
$res = $stmt->fetchAll();
return $res;
}
public function getBrand(){
$sql = "SELECT * FROM brand";
$stmt = $this->connect()->query($sql);
$res = $stmt->fetchAll();
return $res;
}
public function getAll(){
$sql = "SELECT * FROM products";
$stmt = $this->connect()->query($sql);
$res = $stmt->fetchAll();
// remove fetch from here and use it in action for condition after $test->rowCount();
return $res;
}
public function getProductById($id){
$sql = "SELECT * FROM products WHERE id = ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$id]);
$res = $stmt->fetchAll();
return $res;
}
//you will decice what you really want by using this methode ['lorem'];
public function getUsersStmt($brand, $price){
$sql = 'SELECT * FROM products WHERE brand =? AND price =?';
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$brand, $price]);
$names = $stmt->fetchAll();
return $names;
}
// !! i changed this
public function setProduct($name, $price, $stock, $product_images){
$sql = 'INSERT INTO products(product_name, price, stock, product_images) VALUES(?, ?, ?, ?)';
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$name, $price, $stock, $product_images]);
}
public function DelProduct($id){
$sql = 'DELETE FROM products WHERE id = ?';
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$id]);
}
public function Update_Product($product_name, $price, $stock, $id){
$sql = 'UPDATE products set product_name = ?, price = ?, stock = ? WHERE id = ?';
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$product_name, $price, $stock, $id]);
}
// public function getAllPagination($start, $nbrelemnt){
// $sql = 'SELECT * FROM products limit ?,?';
// $stmt = $this->connect()->prepare($sql);
// $stmt->execute([$start, $nbrelemnt]);
// $res = $stmt->fetchAll();
// return $res;
// }
public function getAllPagination($debut){
$stmt = $this->connect()->prepare("SELECT * FROM products limit $debut, 12");
$stmt->execute();
$res = $stmt->fetchAll();
return $res;
}
}
class register_login extends db{
public function register($nom, $email, $pass){
$sql = "INSERT INTO users(nom,email,password) VALUES(?,?,?)";
$stmt = $this->connect()->prepare($sql);
$stmt = $stmt->execute([$nom, $email, $pass]);
}
public function updateUserCheckout($prenom, $codepostal, $adressLiv, $tele, $country, $user_id){
$sql = "UPDATE users SET prenom = ? , codepostal= ?, adresseLiv = ?, tele = ?, contry=? WHERE id=?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$prenom, $codepostal, $adressLiv, $tele, $country, $user_id]);
}
public function login($email, $password){
$sql = "SELECT * FROM users WHERE email = ? AND password = ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$email, $password]);
$res = $stmt->fetchAll();
return $res;
}
public function getUser($id){
$sql = "SELECT * FROM users WHERE id = ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$id]);
$res = $stmt->fetchAll();
return $res;
}
// public function UpdateProfile($id, $nom, $prenom, $email, $newpass){
// }
public function getAdmins($login, $pass){
$sql = "SELECT * FROM admins WHERE login = ? AND pass = ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$login, $pass]);
$res = $stmt->fetchAll();
return $res;
}
}
class cart extends db{
public function getCartProduct($user_id){
$sql = "SELECT * FROM cart WHERE user_id = ? ";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$user_id]);
$res = $stmt->fetchAll();
return $res;
}
public function getCartProductNOtCommender($user_id){
$sql = "SELECT * FROM cart WHERE user_id = ? AND status IS NULL";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$user_id]);
$res = $stmt->fetchAll();
return $res;
}
public function getstock($user_id){
$sql = "SELECT * FROM cart INNER JOIN products on cart.product_id = products.id WHERE cart.user_id =? AND status IS NULL";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$user_id]);
$res = $stmt->fetchAll();
return $res;
}
public function cartcheckid($user_id, $product_id){
$sql = "SELECT * FROM cart WHERE user_id = ? AND product_id = ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$user_id, $product_id]);
$res = $stmt->fetchAll();
return $res;
}
public function addToCart($userid,$product_id, $name, $price, $image, $quantity){
$sql = "INSERT INTO cart(user_id,product_id,name,price,image,quantity) VALUES(?,?,?,?,?,?)";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$userid, $product_id, $name, $price, $image, $quantity]);
}
public function updateCartQnt($qnt, $product_id){
$sql = "UPDATE cart SET quantity = ? WHERE product_id= ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$qnt, $product_id]);
}
public function updateStatus($product_id){
$sql = "UPDATE cart SET status = 'commander' WHERE product_id= ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$product_id]);
}
public function deleteProduct($product_id){
$sql = "DELETE FROM cart WHERE product_id= ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$product_id]);
}
}
class comments extends db{
public function insertComment($comment, $user_id, $product_id){
$sql = "INSERT INTO reviews(commentaire,user_id,product_id,date) VALUES(?,?,?,DATE(NOW()))";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$comment, $user_id, $product_id]);
}
public function delComment($product_id){
$sql = "DELETE FROM reviews WHERE id = ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$product_id]);
}
public function getCommentsAll(){
$sql = "SELECT * FROM reviews";
$stmt = $this->connect()->query($sql);
$res = $stmt->fetchAll();
return $res;
}
public function getCommentsByUserProduct_Id($user_id, $product_id){
$sql = "SELECT * FROM reviews WHERE user_id = ? and product_id = ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$user_id, $product_id]);
$res = $stmt->fetchAll();
return $res;
}
public function getCommentsByProduct_Id($product_id){
$sql = "SELECT * FROM reviews INNER JOIN users on reviews.user_id = users.id WHERE product_id = ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$product_id]);
$res = $stmt->fetchAll();
return $res;
}
public function getCommentsByUser_Id($user_id){
$sql = "SELECT * FROM reviews WHERE user_id = ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$user_id]);
$res = $stmt->fetchAll();
return $res;
}
}
class commande extends db{
// public function insertC($userId, $prix, $commanddate, $etap){
// $sql = "INSERT INTO commande(users_id, prix, command_date, etape) VALUES(?,?,?,?)";
// $stmt = $this->connect()->prepare($sql);
// $stmt->execute([$userId, $prix, $commanddate, $etap]);
// }
public function insertC($product_id,$userId, $prix, $commanddate, $etap){
$sql = "INSERT INTO commande(product_id,user_id, prix, command_date, etape) VALUES(?,?,?,?,?)";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$product_id, $userId, $prix, $commanddate, $etap]);
}
public function getCommande($userId){
$sql = "SELECT * FROM commande INNER JOIN products on commande.product_id = products.id WHERE user_id = ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$userId]);
$res = $stmt->fetchAll();
return $res;
}
}
class admin_dashboard extends db{
#admins
public function getAdmins(){
$sql = "SELECT * FROM admins";
$stmt = $this->connect()->query($sql);
$res = $stmt->fetchAll();
return $res;
}
public function setAdmin($name, $login, $pass, $role){
$sql = "INSERT INTO admins(name, login, pass, role) VALUES(?,?,?,?)";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$name, $login, $pass, $role]);
}
public function dellAdmin($id){
$sql = "DELETE FROM admins WHERE id = ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$id]);
}
#commandes
public function getCommande_admin(){
$sql = "SELECT *,commande.id as idc FROM commande INNER JOIN users on users.id = commande.user_id";
$stmt = $this->connect()->query($sql);
$res = $stmt->fetchAll();
return $res;
}
public function updateCommande($status, $id){
$sql = "UPDATE commande SET etape = ? WHERE id = ?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$status, $id]);
}
}
class blog extends db{
public function getBlogs(){
$sql = "SELECT * FROM blog";
$stmt = $this->connect()->query($sql);
$res = $stmt->fetchAll();
return $res;
}
public function getBlogsById($id){
$sql = "SELECT * FROM blog WHERE id=?";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$id]);
$res = $stmt->fetchAll();
return $res;
}
}
class packs extends db{
public function getPacks(){
$sql = "SELECT * FROM packs";
$stmt = $this->connect()->query($sql);
$res = $stmt->fetchAll();
return $res;
}
}
class suppliers extends db{
public function getSuppliers(){
$sql = "SELECT * FROM supplier";
$stmt = $this->connect()->query($sql);
$res = $stmt->fetchAll();
return $res;
}
}
class press extends db{
public function getPress(){
$sql = "SELECT * FROM press";
$stmt = $this->connect()->query($sql);
$res = $stmt->fetchAll();
return $res;
}
}