34878-vm/db/create_database.php
Flatlogic Bot 8d771ec57c V1
2025-10-11 14:09:06 +00:00

19 lines
619 B
PHP

<?php
require_once __DIR__ . '/config.php';
try {
// Connect to MySQL server without specifying a database
$pdo = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);
echo "Connected to MySQL server successfully.\n";
// Create the database if it doesn't exist
$pdo->exec("CREATE DATABASE IF NOT EXISTS `" . DB_NAME . "` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;");
echo "Database '" . DB_NAME . "' created or already exists.\n";
} catch (PDOException $e) {
die("Database creation failed: " . $e->getMessage() . "\n");
}