From 669b5b3859005839bd3205c271cbe63e3c9079c4 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Fri, 1 Jun 2018 20:43:25 +0200 Subject: [PATCH] extracted db connection --- .gitignore | 2 ++ entry.php | 13 +------------ php/generateLink.php | 13 +------------ ~dbConnect.php | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 24 deletions(-) create mode 100644 .gitignore create mode 100644 ~dbConnect.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c7f7bd3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +dbConnect.php diff --git a/entry.php b/entry.php index 5945bfe..8ee12c5 100644 --- a/entry.php +++ b/entry.php @@ -13,18 +13,7 @@ } function consumeTan($tan) { - //Stelle DB verbindung her - $user = 'root'; - $password = 'root'; - $db = 'friendsbook'; - $host = 'localhost'; - $port = 3306; - - $database = new mysqli($host, $user, $password, $db, $port); - - if ($database->connect_error) { - die('Connect Error (' . $database->connect_errno . ') ' . $database->connect_error); - } + require('dbConnect.php'); //Erstellt variable mit dem namen $database //Stelle sicher dass die Tan noch verfügbar ist. $abfrage = "SELECT `used`, `tan` FROM `tans` WHERE `tan` = '" . $tan . "'"; diff --git a/php/generateLink.php b/php/generateLink.php index 03f9e7e..2bfb25d 100644 --- a/php/generateLink.php +++ b/php/generateLink.php @@ -12,18 +12,7 @@ echo json_encode($HTMLJSON); function insertTan($tan) { - //Stelle DB verbindung her - $user = 'root'; - $password = 'root'; - $db = 'friendsbook'; - $host = 'localhost'; - $port = 3306; - - $database = new mysqli($host, $user, $password, $db, $port); - - if ($database->connect_error) { - die('Connect Error (' . $database->connect_errno . ') ' . $database->connect_error); - } + require('../dbConnect.php'); //Erstellt variable mit dem namen $database $stmt = $database->prepare("INSERT INTO tans (tan, used) VALUES (?, ?)"); diff --git a/~dbConnect.php b/~dbConnect.php new file mode 100644 index 0000000..888225d --- /dev/null +++ b/~dbConnect.php @@ -0,0 +1,18 @@ +connect_error) { + die('Connect Error (' . $database->connect_errno . ') ' . $database->connect_error); +} + +?> \ No newline at end of file