36766-vm/db/migration_017_create_order_items_table.php
Flatlogic Bot 6c14b2436f 2.0
2025-12-18 09:40:37 +00:00

23 lines
709 B
PHP

<?php
require_once 'config.php';
try {
$db = db();
$sql = "
CREATE TABLE IF NOT EXISTS `order_items` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`order_id` INT NOT NULL,
`product_id` INT NOT NULL,
`quantity` INT NOT NULL,
`price` DECIMAL(10, 2) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`order_id`) REFERENCES `orders`(`id`),
FOREIGN KEY (`product_id`) REFERENCES `products`(`id`)
);
";
$db->exec($sql);
echo "Table 'order_items' created successfully." . PHP_EOL;
} catch (PDOException $e) {
die("Error creating table: " . $e->getMessage());
}
?>