87 lines
2.9 KiB
PHP
87 lines
2.9 KiB
PHP
<?php
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
// Verbindung zur MySQL-Datenbank herstellen
|
|
$servername = $_POST['servername'];
|
|
$username = $_POST['username'];
|
|
$password = $_POST['password'];
|
|
$database = $_POST['database'];
|
|
|
|
$conn = new mysqli($servername, $username, $password);
|
|
|
|
// Überprüfen, ob die Verbindung erfolgreich war
|
|
if ($conn->connect_error) {
|
|
die("Connection failed: " . $conn->connect_error);
|
|
}
|
|
|
|
// Datenbank erstellen
|
|
$sqlCreateDb = "CREATE DATABASE IF NOT EXISTS $database";
|
|
if ($conn->query($sqlCreateDb) === TRUE) {
|
|
// Datenbank wurde erfolgreich erstellt
|
|
|
|
// Datenbanktabellen erstellen
|
|
$conn->select_db($database);
|
|
$sqlCreateTable = "
|
|
CREATE TABLE IF NOT EXISTS articles (
|
|
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
manufacturer VARCHAR(255) NOT NULL,
|
|
set_name VARCHAR(255),
|
|
article_number VARCHAR(255) NOT NULL,
|
|
ean_barcode VARCHAR(255),
|
|
part1 VARCHAR(255),
|
|
part1_ean VARCHAR(255),
|
|
part2 VARCHAR(255),
|
|
part2_ean VARCHAR(255),
|
|
part3 VARCHAR(255),
|
|
part3_ean VARCHAR(255),
|
|
part4 VARCHAR(255),
|
|
part4_ean VARCHAR(255),
|
|
quantity INT(6)
|
|
)
|
|
";
|
|
if ($conn->query($sqlCreateTable) === TRUE) {
|
|
// Datenbank und Tabellen wurden erfolgreich erstellt
|
|
// Konfigurationsdatei schreiben
|
|
$configFile = '../config/config.php';
|
|
$configData = '<?php return ' . var_export($_POST, true) . ';';
|
|
file_put_contents($configFile, $configData);
|
|
|
|
// Weiterleitung zur Index-Seite
|
|
header('Location: index.php');
|
|
exit;
|
|
} else {
|
|
echo "Error creating table: " . $conn->error;
|
|
}
|
|
} else {
|
|
echo "Error creating database: " . $conn->error;
|
|
}
|
|
|
|
// Verbindung schließen
|
|
$conn->close();
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="install.css">
|
|
<title>Install</title>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="box">
|
|
<h2>Database Configuration</h2>
|
|
<form method="post">
|
|
<label>Servername:</label>
|
|
<input type="text" name="servername" required><br><br>
|
|
<label>Username:</label>
|
|
<input type="text" name="username" required><br><br>
|
|
<label>Password:</label>
|
|
<input type="password" name="password"><br><br>
|
|
<label>Database:</label>
|
|
<input type="text" name="database" required><br><br>
|
|
<input type="submit" value="Submit">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|