-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.php
executable file
·30 lines (18 loc) · 1.08 KB
/
database.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
<?php
include "./config.php";
// Load and initialize the database.
if (file_exists($config["database_location"]) == false) { // If the database file doesn't exist, create it.
$item_database_file = fopen($config["database_location"], "w") or die("Unable to create database file!"); // Create the file.
fwrite($item_database_file, "a:0:{}"); // Set the contents of the database file to a blank database.
fclose($item_database_file); // Close the database file.
}
if (file_exists($config["database_location"]) == true) { // Check to see if the item database file exists. The database should have been created in the previous step if it didn't already exists.
$item_database = unserialize(file_get_contents($config["database_location"])); // Load the database from the disk.
if (!isset($item_database[$username])) { // Check to see if the user already exists in the item database.
$item_database[$username] = array();
}
} else {
echo "<p>The database failed to load</p>"; // Inform the user that the database failed to load.
exit(); // Terminate the script.
}
?>