-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_db.php
More file actions
26 lines (21 loc) · 791 Bytes
/
Copy pathsetup_db.php
File metadata and controls
26 lines (21 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
if (php_sapi_name() !== 'cli' && !in_array($_SERVER['REMOTE_ADDR'] ?? '', ['127.0.0.1', '::1'])) {
http_response_code(403);
die("Setup can only be run from the command line or localhost.");
}
$conn = new mysqli('127.0.0.1', 'root', '', '');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$conn->query("CREATE DATABASE IF NOT EXISTS cerberus_db");
$conn->select_db("cerberus_db");
$schema = file_get_contents(__DIR__ . '/database/schema.sql');
if ($conn->multi_query($schema)) {
while ($conn->more_results() && $conn->next_result()) {;}
}
$seed = file_get_contents(__DIR__ . '/database/seed.sql');
if ($conn->multi_query($seed)) {
while ($conn->more_results() && $conn->next_result()) {;}
}
echo "Database setup complete.";
?>