37145-vm/db/database.php
2025-12-26 09:00:50 +00:00

24 lines
703 B
PHP

<?php
require_once 'config.php';
try {
$conn = db();
// Create database if it doesn't exist
$conn->exec("CREATE DATABASE IF NOT EXISTS " . getenv('DB_NAME'));
$conn->exec("USE " . getenv('DB_NAME'));
// Create table for files
$sql = "CREATE TABLE IF NOT EXISTS files (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
filename VARCHAR(255) NOT NULL,
filesize INT(11) NOT NULL,
filetype VARCHAR(50) NOT NULL,
upload_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
$conn->exec($sql);
echo "Database and table created successfully.";
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
?>