-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.php
40 lines (33 loc) · 942 Bytes
/
setup.php
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require_once "env.php";
require_once "migrations.php";
// Attempt to connect to MySQL database
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
foreach ($migrations as $migration) {
try {
$stmt = mysqli_prepare($link, $migration['query']);
if(mysqli_stmt_execute($stmt))
{
echo "Executed migration for table: " . $migration['table'] . "\n";
}
else{
echo "Something went wrong with table: " . $migration['table'] . "\n";
mysqli_close($link);
die();
}
}
catch (Exception $e)
{
echo "Something went wrong:\n" . $e->getMessage() . "\n";
mysqli_close($link);
die();
}
}
// Close connection
mysqli_close($link);
echo "\n";
echo "Migrations executed successfully!\n";