Add project files
This commit is contained in:
59
00_uebungs-files/03_docker-compose/src/db-test.php
Normal file
59
00_uebungs-files/03_docker-compose/src/db-test.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
$host = getenv('DB_HOST') ?: 'db';
|
||||
$user = getenv('DB_USER') ?: 'root';
|
||||
$pass = getenv('DB_PASS') ?: 'secret';
|
||||
$dbname = getenv('DB_NAME') ?: 'testdb';
|
||||
|
||||
echo "<h1>Datenbank-Verbindungstest</h1>";
|
||||
echo "<p>Verbindungsversuch zu: $host</p>";
|
||||
|
||||
try {
|
||||
// Verbindung erstellen
|
||||
$conn = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
|
||||
|
||||
// PDO-Fehlerbehandlung aktivieren
|
||||
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
echo "<div style='color:green;'>Verbindung erfolgreich!</div>";
|
||||
|
||||
// Prüfen, ob Testtabelle existiert, sonst erstellen
|
||||
$stmt = $conn->query("SHOW TABLES LIKE 'test_table'");
|
||||
if ($stmt->rowCount() == 0) {
|
||||
$conn->exec("CREATE TABLE test_table (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
message VARCHAR(255),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)");
|
||||
$conn->exec("INSERT INTO test_table (message) VALUES ('Testdaten 1')");
|
||||
$conn->exec("INSERT INTO test_table (message) VALUES ('Testdaten 2')");
|
||||
echo "<p>Testtabelle erstellt und mit Daten gefüllt.</p>";
|
||||
}
|
||||
|
||||
// Daten auslesen
|
||||
$stmt = $conn->query("SELECT * FROM test_table");
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo "<h2>Daten aus der Datenbank:</h2>";
|
||||
echo "<table border='1'>";
|
||||
echo "<tr><th>ID</th><th>Nachricht</th><th>Erstellt am</th></tr>";
|
||||
|
||||
foreach ($rows as $row) {
|
||||
echo "<tr>";
|
||||
echo "<td>" . $row['id'] . "</td>";
|
||||
echo "<td>" . $row['message'] . "</td>";
|
||||
echo "<td>" . $row['created_at'] . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
echo "</table>";
|
||||
|
||||
} catch(PDOException $e) {
|
||||
echo "<div style='color:red;'>Verbindungsfehler: " . $e->getMessage() . "</div>";
|
||||
}
|
||||
|
||||
// Verbindung schließen
|
||||
$conn = null;
|
||||
?>
|
||||
|
||||
<p>Seite geladen um: <?php echo date('H:i:s'); ?></p>
|
||||
<p><a href="index.php">Zurück zur Startseite</a></p>
|
||||
29
00_uebungs-files/03_docker-compose/src/image-test.php
Normal file
29
00_uebungs-files/03_docker-compose/src/image-test.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
// Test für GD Extension
|
||||
header('Content-Type: image/png');
|
||||
|
||||
// Canvas erstellen (300x200px)
|
||||
$image = imagecreatetruecolor(300, 200);
|
||||
|
||||
// Farben definieren
|
||||
$background = imagecolorallocate($image, 0, 153, 204);
|
||||
$text_color = imagecolorallocate($image, 255, 255, 255);
|
||||
$border_color = imagecolorallocate($image, 0, 0, 0);
|
||||
|
||||
// Hintergrund füllen
|
||||
imagefill($image, 0, 0, $background);
|
||||
|
||||
// Rahmen zeichnen
|
||||
imagerectangle($image, 0, 0, 299, 199, $border_color);
|
||||
|
||||
// Text schreiben
|
||||
$text = "GD funktioniert!";
|
||||
imagestring($image, 5, 60, 80, $text, $text_color);
|
||||
|
||||
// Zeit anzeigen
|
||||
$time = date('H:i:s');
|
||||
imagestring($image, 3, 100, 120, "Zeit: $time", $text_color);
|
||||
|
||||
// Bild ausgeben
|
||||
imagepng($image);
|
||||
imagedestroy($image);
|
||||
36
00_uebungs-files/03_docker-compose/src/index.php
Normal file
36
00_uebungs-files/03_docker-compose/src/index.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>PHP Docker Demo</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
|
||||
h1 { color: #0066cc; }
|
||||
.info { background-color: #f0f0f0; padding: 15px; border-radius: 5px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>PHP-FPM mit Nginx Docker Demo</h1>
|
||||
|
||||
<div class="info">
|
||||
<p>PHP Version: <?php echo phpversion(); ?></p>
|
||||
<p>Server Software: <?php echo $_SERVER['SERVER_SOFTWARE']; ?></p>
|
||||
<p>Ausgeführt von: <?php echo exec('whoami'); ?></p>
|
||||
<p>Zeitstempel: <?php echo date('Y-m-d H:i:s'); ?></p>
|
||||
</div>
|
||||
|
||||
<h2>Extension Tests</h2>
|
||||
<ul>
|
||||
<li><a href="image-test.php">GD Image Test</a> (benötigt GD Extension)</li>
|
||||
<li><a href="db-test.php">Datenbank-Test</a> (benötigt MySQL/MariaDB Verbindung)</li>
|
||||
</ul>
|
||||
|
||||
<h3>Installierte PHP Extensions:</h3>
|
||||
<ul>
|
||||
<?php foreach(get_loaded_extensions() as $ext): ?>
|
||||
<li><?php echo $ext; ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user