Compare commits

3 Commits

Author SHA1 Message Date
b8f1c32a22 init.php connection to db with ssh 2026-04-15 14:56:44 +02:00
0aeee9a168 gitignore added 2026-04-15 14:42:07 +02:00
luptmoor
1f8e3935bb hostname as var 2026-04-15 16:23:18 +02:00
2 changed files with 15 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.env

View File

@@ -1,6 +1,18 @@
<?php <?php
$host = 'webgis-db'; // Matches the service name in docker-compose
$envFile = __DIR__ . '/.env';
if (file_exists($envFile)) {
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) continue;
list($key, $value) = array_map('trim', explode('=', $line, 2));
putenv("$key=$value");
}
}
$host = getenv('POSTGRES_HOST');
$port = getenv('POSTGRES_PORT');
$db = getenv('POSTGRES_DB'); $db = getenv('POSTGRES_DB');
$user = getenv('POSTGRES_USER'); $user = getenv('POSTGRES_USER');
$pass = getenv('POSTGRES_PASSWORD'); $pass = getenv('POSTGRES_PASSWORD');
@@ -16,7 +28,7 @@ $pass = getenv('POSTGRES_PASSWORD');
PDO::ATTR_EMULATE_PREPARES => false PDO::ATTR_EMULATE_PREPARES => false
]; ];
$dsn = "pgsql:host=localhost;dbname=$db;port=5432"; $dsn = "pgsql:host=$host;dbname=$db;port=$port";
$pdo = new PDO($dsn, $user, $pass, $opt); $pdo = new PDO($dsn, $user, $pass, $opt);
// Error-Message // Error-Message