From 94506f031c348c3fd0e1f2bb33e8b88dc0d4659f Mon Sep 17 00:00:00 2001 From: Thedro Neely Date: Fri, 11 Nov 2022 11:54:42 -0500 Subject: database: Swap to sqlite --- .gitignore | 1 + Makefile | 4 ++++ app/controllers/contact.controller.php | 1 + bootstrap/database/Connection.php | 8 ++++---- config.php | 7 +++---- database/contactform.sql | 8 ++++++++ 6 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 database/contactform.sql diff --git a/.gitignore b/.gitignore index 41b9e86..0355f3b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ **/generators/exoference/*.html .hugo_build.lock /cockpit +/database /storage /vendor config.php diff --git a/Makefile b/Makefile index aa991c3..d412684 100644 --- a/Makefile +++ b/Makefile @@ -21,4 +21,8 @@ cockpit: sed --in-place "s|^hugo_base_dir.*|hugo_base_dir: $$PWD/generators/hugo|" cockpit/addons/Hugo/config.yaml sed --in-place "s|^hugo_theme.*|hugo_theme: tdro|" cockpit/addons/Hugo/config.yaml +migration: + sqlite3 database/sqlite.db < database/contactform.sql + sed --in-place "s|'sql:;dbname=sql_database'|'sqlite:' . __DIR__ . '/database/sqlite.db'|" config.php + .PHONY: generators cockpit diff --git a/app/controllers/contact.controller.php b/app/controllers/contact.controller.php index 797cccd..8a1a62e 100644 --- a/app/controllers/contact.controller.php +++ b/app/controllers/contact.controller.php @@ -30,6 +30,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $spam = false; include '../app/views/contact.view.php'; + fastcgi_finish_request(); $contact['database']->insert( diff --git a/bootstrap/database/Connection.php b/bootstrap/database/Connection.php index deec2c6..3093d85 100644 --- a/bootstrap/database/Connection.php +++ b/bootstrap/database/Connection.php @@ -2,17 +2,17 @@ class Connection { - public static function make($config) + public static function make(array $config) { try { return new PDO( - $config['connection'].';dbname='.$config['name'], + $config['dsn'], $config['username'], $config['password'], $config['options'] ); - } catch (PDOException $e) { - error_log($e->getMessage()); + } catch (PDOException $error) { + error_log($error->getMessage()); } } } diff --git a/config.php b/config.php index 715eb48..7af1076 100644 --- a/config.php +++ b/config.php @@ -2,10 +2,9 @@ return [ 'database' => [ - 'name' => 'pgsql_database', - 'username' => 'pgsql_username', - 'password' => 'pgsql_password', - 'connection' => 'pgsql:', + 'dsn' => 'sql:;dbname=sql_database', + 'username' => 'sql_username', + 'password' => 'sql_password', 'options' => [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ] diff --git a/database/contactform.sql b/database/contactform.sql new file mode 100644 index 0000000..0749014 --- /dev/null +++ b/database/contactform.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS contactform ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT, + email TEXT NOT NULL, + message TEXT NOT NULL, + date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL +); + -- cgit v1.2.3