create database connection
This commit is contained in:
parent
507f65dcb0
commit
c949aebc85
@ -2,10 +2,37 @@
|
||||
|
||||
$uniqueID = uniqid();
|
||||
$resultStr = "Neuer eintrag über: http://localhost/github/ipr-projekt/entry.php?tan=";
|
||||
$resultStr = $resultStr . uniqid();
|
||||
$resultStr = $resultStr . $uniqueID;
|
||||
|
||||
insertTan($uniqueID);
|
||||
|
||||
$HTMLJSON = array('html' => $resultStr);
|
||||
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
1
sql/createDatabase.sql
Normal 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;
|
Loading…
Reference in New Issue
Block a user