23 lines
709 B
PHP
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());
|
|
}
|
|
?>
|