extracted db connection

This commit is contained in:
Marcel Schwarz 2018-06-01 20:43:25 +02:00
parent 8a1b946f8e
commit 669b5b3859
4 changed files with 22 additions and 24 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
dbConnect.php

View File

@ -13,18 +13,7 @@
} }
function consumeTan($tan) { function consumeTan($tan) {
//Stelle DB verbindung her require('dbConnect.php'); //Erstellt variable mit dem namen $database
$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);
}
//Stelle sicher dass die Tan noch verfügbar ist. //Stelle sicher dass die Tan noch verfügbar ist.
$abfrage = "SELECT `used`, `tan` FROM `tans` WHERE `tan` = '" . $tan . "'"; $abfrage = "SELECT `used`, `tan` FROM `tans` WHERE `tan` = '" . $tan . "'";

View File

@ -12,18 +12,7 @@
echo json_encode($HTMLJSON); echo json_encode($HTMLJSON);
function insertTan($tan) { function insertTan($tan) {
//Stelle DB verbindung her require('../dbConnect.php'); //Erstellt variable mit dem namen $database
$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);
}
$stmt = $database->prepare("INSERT INTO tans (tan, used) VALUES (?, ?)"); $stmt = $database->prepare("INSERT INTO tans (tan, used) VALUES (?, ?)");

18
~dbConnect.php Normal file
View File

@ -0,0 +1,18 @@
<?php
//Create DB connection.
//This creates a usable "database" - Variable as mysqli Objekt
//simply remove the "~" in front of the filename
$user = 'user';
$password = 'password';
$db = 'database name';
$host = 'ip or domain';
$port = 3306;
$database = new mysqli($host, $user, $password, $db, $port);
if ($database->connect_error) {
die('Connect Error (' . $database->connect_errno . ') ' . $database->connect_error);
}
?>