35996-vm/db/create_messages_table.php
Flatlogic Bot da3d35fbf3 v1
2025-11-22 12:04:14 +00:00

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());
}