20 lines
641 B
PHP
20 lines
641 B
PHP
<?php
|
|
require 'config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
$sql = "CREATE TABLE IF NOT EXISTS messages (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
sender_id INT NOT NULL,
|
|
recipient_id INT NOT NULL,
|
|
message TEXT NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
FOREIGN KEY (recipient_id) REFERENCES users(id) ON DELETE CASCADE
|
|
)";
|
|
$pdo->exec($sql);
|
|
echo "INFO: `messages` table created or already exists.";
|
|
} catch (PDOException $e) {
|
|
die("ERROR: Could not connect to the database: " . $e->getMessage());
|
|
}
|