<?php
$servername = "localhost";
$username = "root";
$password = "";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error . "\n");
}

// Create database
$sql = "CREATE DATABASE IF NOT EXISTS bm_business_db";
if ($conn->query($sql) === TRUE) {
    echo "Database created successfully\n";
} else {
    echo "Error creating database: " . $conn->error . "\n";
}

$conn->close();

// Now connect to the new DB and import SQL
$conn = new mysqli($servername, $username, $password, "bm_business_db");
if ($conn->connect_error) {
    die("Connection failed after creating DB: " . $conn->connect_error . "\n");
}

$sql_content = file_get_contents('database.sql');
if ($conn->multi_query($sql_content)) {
    echo "SQL script database.sql imported successfully.\n";
    while ($conn->next_result()) {;} // flush multi queries
} else {
    echo "Error importing SQL script: " . $conn->error . "\n";
}

$conn->close();
?>
