23 lines
648 B
PHP
23 lines
648 B
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
try {
|
|
// Connect to MySQL without specifying a database
|
|
$pdo = new PDO('mysql:host='.DB_HOST, DB_USER, DB_PASS, [
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
]);
|
|
|
|
// Create the database
|
|
$pdo->exec('CREATE DATABASE IF NOT EXISTS '.DB_NAME);
|
|
|
|
// Now connect to the newly created database
|
|
$pdo = db();
|
|
|
|
// Execute the initial schema
|
|
$sql = file_get_contents('db/migrations/001_initial_schema.sql');
|
|
$pdo->exec($sql);
|
|
|
|
echo "Database setup completed successfully.";
|
|
} catch (PDOException $e) {
|
|
die("Database setup failed: " . $e->getMessage());
|
|
} |