aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgi Nikolov <ggeorgi60@gmail.com>2025-01-17 20:07:55 +0200
committerGeorgi Nikolov <ggeorgi60@gmail.com>2025-01-17 20:07:55 +0200
commitd3833d2a50371b5ebc989ca9b4a999a5f7f74c98 (patch)
tree0c5b1716b30098b6dab86df18e50816e9fbbe8f0
parent892eca73a66294ffadd987c5f6d554f738cff287 (diff)
downloadnowayforward_human-d3833d2a50371b5ebc989ca9b4a999a5f7f74c98.tar
nowayforward_human-d3833d2a50371b5ebc989ca9b4a999a5f7f74c98.tar.gz
nowayforward_human-d3833d2a50371b5ebc989ca9b4a999a5f7f74c98.zip
Added example mariadb code in php
-rw-r--r--migrations/initial.sql26
-rw-r--r--src/archive_page.php12
2 files changed, 37 insertions, 1 deletions
diff --git a/migrations/initial.sql b/migrations/initial.sql
new file mode 100644
index 0000000..9899f63
--- /dev/null
+++ b/migrations/initial.sql
@@ -0,0 +1,26 @@
+SET @username = 'default';
+SET @password = 'Password1234';
+
+-- Check if the user exists
+SELECT COUNT(*) INTO @user_exists
+FROM mysql.user
+WHERE user = @username AND host = 'localhost';
+
+-- Create the user if it does not exist
+IF @user_exists = 0 THEN
+ CREATE USER @username@'localhost' IDENTIFIED BY @password;
+END IF;
+
+GRANT ALL PRIVILEGES ON db.* TO @username@'localhost';
+FLUSH PRIVILEGES;
+
+-- Create the database if it does not exist
+CREATE DATABASE IF NOT EXISTS db;
+USE db;
+
+-- Create the users table if it does not exist
+CREATE TABLE IF NOT EXISTS users (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ username VARCHAR(50) NOT NULL UNIQUE,
+ password VARCHAR(255) NOT NULL
+);
diff --git a/src/archive_page.php b/src/archive_page.php
index bd1f872..9c37fb0 100644
--- a/src/archive_page.php
+++ b/src/archive_page.php
@@ -42,9 +42,19 @@
}
$WEBSITE_CATEGORY = 'page_url';
+ $DATABASE_NAME = 'db';
+ $TABLE_NAME = 'users';
$website_url = $_POST[$WEBSITE_CATEGORY];
$website_exists = does_website_exist($website_url) ? "true" : "false";
- echo "Website exists: $website_exists";
+ echo "Website exists: $website_exists" . "<br/>";
+
+ try {
+ $db = new PDO("mysql:host=localhost;dbname=$DATABASE_NAME", $user, $password);
+ echo $db->query("DESCRIBE $TABLE_NAME");
+ } catch (PDOException $e) {
+ print "Error!: " . $e->getMessage() . "<br/>";
+ die();
+ }
?>
</p>
</body>