This repository was archived by the owner on Jul 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct.php
More file actions
49 lines (38 loc) · 1.46 KB
/
Copy pathProduct.php
File metadata and controls
49 lines (38 loc) · 1.46 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
<?php
class Product
{
private $conn;
public function __construct(PDO $dbConnection) {
$this->conn = $dbConnection;
}
public function create($id, $name, $description, $price, $supplier_id) {
$query = "INSERT INTO product (id, name, description, prince, supplier_id)
VALUES (:id, :name, :description, :price, :supplier_id);";
$stmt = $this->conn->prepare($query);
$stmt->bindValue(":id", $id);
$stmt->bindValue(":name", $name);
$stmt->bindValue(":description", $description);
$stmt->bindValue(":price", $price);
$stmt->bindValue(":supplier_id", $supplier_id);
return $stmt->execute();
}
public function getAll() {
$query = "SELECT * FROM product;";
$stmt = $this->conn->prepare($query);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_OBJ);
}
public function getById($id) {
$query = "SELECT product.*, c.name AS category_name,
s.name AS supplier_name, s.email AS supplier_email,
s.phone AS supplier_phone
FROM product
INNER JOIN product_to_category ptc ON product.id = ptc.product_id
INNER JOIN product_category c ON ptc.category_id = c.id
INNER JOIN supplier s ON product.supplier_id = s.id
WHERE product.id = :id;";
$stmt = $this->conn->prepare($query);
$stmt->execute(['id' => $id]);
return $stmt->fetch(PDO::FETCH_OBJ);
}
}