aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThedro Neely <thedroneely@gmail.com>2022-11-11 11:54:42 -0500
committerThedro Neely <thedroneely@gmail.com>2022-11-11 11:54:42 -0500
commit94506f031c348c3fd0e1f2bb33e8b88dc0d4659f (patch)
tree22b71d490445c7285dbaa3eec939391b6d327a96
parentabdbac031912a395c7524ad0e6f5c70c918531b2 (diff)
downloadthedroneely.com-94506f031c348c3fd0e1f2bb33e8b88dc0d4659f.tar.gz
thedroneely.com-94506f031c348c3fd0e1f2bb33e8b88dc0d4659f.tar.bz2
thedroneely.com-94506f031c348c3fd0e1f2bb33e8b88dc0d4659f.zip
database: Swap to sqlite
-rw-r--r--.gitignore1
-rw-r--r--Makefile4
-rw-r--r--app/controllers/contact.controller.php1
-rw-r--r--bootstrap/database/Connection.php8
-rw-r--r--config.php7
-rw-r--r--database/contactform.sql8
6 files changed, 21 insertions, 8 deletions
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
+);
+