create database connection

This commit is contained in:
Marcel Schwarz 2018-05-26 15:09:18 +02:00
parent 507f65dcb0
commit c949aebc85
2 changed files with 29 additions and 1 deletions

View File

@ -2,10 +2,37 @@
$uniqueID = uniqid(); $uniqueID = uniqid();
$resultStr = "Neuer eintrag über: http://localhost/github/ipr-projekt/entry.php?tan="; $resultStr = "Neuer eintrag über: http://localhost/github/ipr-projekt/entry.php?tan=";
$resultStr = $resultStr . uniqid(); $resultStr = $resultStr . $uniqueID;
insertTan($uniqueID);
$HTMLJSON = array('html' => $resultStr); $HTMLJSON = array('html' => $resultStr);
echo json_encode($HTMLJSON); 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);
}
$stmt = $database->prepare("INSERT INTO tans (tan, used) VALUES (?, ?)");
$false = false;
$stmt->bind_param("si", $tan, $false);
try {
$stmt->execute();
} catch (PDOException $e) {
$e->getMessage();
}
}
?> ?>

1
sql/createDatabase.sql Normal file
View File

@ -0,0 +1 @@
CREATE TABLE `friendsbook`.`tans` ( `id` INT NOT NULL AUTO_INCREMENT , `tan` VARCHAR(13) NOT NULL , `used` BOOLEAN NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;