add saving registrations to sqlite

This commit is contained in:
2018-02-11 20:22:40 +01:00
parent f306dda4f9
commit bd06342ccf
3 changed files with 41 additions and 5 deletions

29
database.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
$db_file = "db_file.sqlite";
// create database file when not existent yet
if (!file_exists($db_file)) {
$db = new PDO('sqlite:' . $db_file);
$db->exec("CREATE TABLE registrations(
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT,
last_name TEXT,
username TEXT,
note TEXT,
email TEXT,
verify_token TEXT,
request_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP)");
}
else {
// establish connection
$db = new PDO('sqlite:' . $db_file);
$ins_stmt = $db->prepare("INSERT INTO registrations
(first_name, last_name, note, email, username, verify_token)
VALUES (:first_name, :last_name, :note, :email, :username, :verify_token);
}
// set writeable when not set already
if (!is_writable($db_file)) {
chmod($db_file, 0777);
}
?>