diff --git a/api/api.php b/api/api.php index 0fe2937..789761b 100755 --- a/api/api.php +++ b/api/api.php @@ -65,7 +65,7 @@ class gbAPI { return false; } - function answer($status, $data) { + function answer($status, $data = []) { http_response_code($status); Header ("Content-Type: application/json; charset=UTF-8"); diff --git a/api/setup/save.php b/api/setup/save.php index b6836a1..7f6dc19 100755 --- a/api/setup/save.php +++ b/api/setup/save.php @@ -37,4 +37,21 @@ $hash = password_hash($password); // CREATE DATABASE STRUCTURE -file_get_contents(APP_PATH . "db_structure.sql"); +$sql_file = file_get_contents(APP_PATH . "db_structure.sql"); + +$db_path = APP_PATH . "database.db"; + +$db = new PDO("sqlite:" . $db_path); +$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + +$db = exec($sql_file); + + + +// INSERT USER +$command = "INSERT INTO users (username, password, owner) VALUES (:username, :password, :owner)"; + +$stmt = $db->prepare($command); +$stmt->execute([":username" => $username, ":password" => $hash, ":owner" => 1]); + +$api->answer(200); \ No newline at end of file