File manager - Edit - /home/webapp69.cm.in.th/u69319090044/shop/classes/Product.php
Back
<?php // classes/Product.php - Product management module require_once __DIR__ . '/Database.php'; class Product { private $db; public function __construct() { $this->db = Database::getInstance()->getConnection(); } public function getAll() { $stmt = $this->db->query("SELECT * FROM products ORDER BY name ASC"); return $stmt->fetchAll(); } public function getById($id) { $stmt = $this->db->prepare("SELECT * FROM products WHERE id = ?"); $stmt->execute([$id]); return $stmt->fetch(); } public function create($name, $description, $price, $stock, $image_url, $size = 'Free Size') { $stmt = $this->db->prepare("INSERT INTO products (name, description, price, size, stock, image_url) VALUES (?, ?, ?, ?, ?, ?)"); return $stmt->execute([$name, $description, $price, $size, $stock, $image_url]); } public function update($id, $name, $description, $price, $stock, $image_url, $size = 'Free Size') { $stmt = $this->db->prepare("UPDATE products SET name = ?, description = ?, price = ?, size = ?, stock = ?, image_url = ? WHERE id = ?"); return $stmt->execute([$name, $description, $price, $size, $stock, $image_url, $id]); } public function delete($id) { $stmt = $this->db->prepare("DELETE FROM products WHERE id = ?"); return $stmt->execute([$id]); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.22 |
proxy
|
phpinfo
|
Settings