connect_error) { throw new Exception("فشل الاتصال: " . $conn->connect_error); } // إضافة منتج جديد $stmt = $conn->prepare("INSERT INTO products (name, description, price, stock, category) VALUES (?, ?, ?, ?, ?)"); $name = "زيت اللافندر الطبيعي"; $description = "زيت لافندر طبيعي 100% للعناية بالبشرة والشعر"; $price = 149.99; $stock = 50; $category = "essential_oils"; $stmt->bind_param("ssdis", $name, $description, $price, $stock, $category); if ($stmt->execute()) { $product_id = $conn->insert_id; echo "تم إضافة المنتج بنجاح (ID: $product_id)\n"; } // استرجاع المنتج $stmt = $conn->prepare("SELECT * FROM products WHERE id = ?"); $stmt->bind_param("i", $product_id); $stmt->execute(); $result = $stmt->get_result(); $product = $result->fetch_assoc(); echo "\nبيانات المنتج:\n"; echo "الاسم: " . $product['name'] . "\n"; echo "السعر: " . $product['price'] . " جنيه\n"; echo "المخزون: " . $product['stock'] . " قطعة\n"; // تحديث المنتج $new_price = 139.99; $new_stock = 45; $stmt = $conn->prepare("UPDATE products SET price = ?, stock = ? WHERE id = ?"); $stmt->bind_param("dii", $new_price, $new_stock, $product_id); if ($stmt->execute()) { echo "\nتم تحديث المنتج بنجاح\n"; } // التحقق من التحديث $stmt = $conn->prepare("SELECT price, stock FROM products WHERE id = ?"); $stmt->bind_param("i", $product_id); $stmt->execute(); $result = $stmt->get_result(); $updated_product = $result->fetch_assoc(); echo "\nبيانات المنتج بعد التحديث:\n"; echo "السعر الجديد: " . $updated_product['price'] . " جنيه\n"; echo "المخزون الجديد: " . $updated_product['stock'] . " قطعة\n"; // حذف المنتج $stmt = $conn->prepare("DELETE FROM products WHERE id = ?"); $stmt->bind_param("i", $product_id); if ($stmt->execute()) { echo "\nتم حذف المنتج بنجاح\n"; } // التحقق من الحذف $stmt = $conn->prepare("SELECT COUNT(*) as count FROM products WHERE id = ?"); $stmt->bind_param("i", $product_id); $stmt->execute(); $result = $stmt->get_result(); $count = $result->fetch_assoc()['count']; echo "التحقق من الحذف: " . ($count == 0 ? "ناجح ✓" : "فشل ✗") . "\n"; $conn->close(); } catch (Exception $e) { echo "خطأ: " . $e->getMessage() . "\n"; }