init adapted to server
This commit is contained in:
36
init.php
36
init.php
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Reads .env File
|
// Reads Environment Configfile
|
||||||
$envFile = __DIR__ . '/.env';
|
$envFile = __DIR__ . '/.env';
|
||||||
if (file_exists($envFile)) {
|
if (file_exists($envFile)) {
|
||||||
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
@@ -11,28 +11,30 @@ if (file_exists($envFile)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Defines Environment Variables
|
||||||
$host = getenv('POSTGRES_HOST');
|
$host = getenv('POSTGRES_HOST');
|
||||||
$port = getenv('POSTGRES_PORT');
|
$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');
|
||||||
|
|
||||||
ob_start();
|
// Output Buffering and Session Start
|
||||||
session_start();
|
ob_start();
|
||||||
|
session_start();
|
||||||
|
|
||||||
try {
|
// Initializes Database Connection
|
||||||
|
try {
|
||||||
$opt = [
|
$opt = [
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||||
PDO::ATTR_EMULATE_PREPARES => false
|
PDO::ATTR_EMULATE_PREPARES => false
|
||||||
];
|
];
|
||||||
|
$dsn = "pgsql:host=$host;dbname=$db;port=$port";
|
||||||
$dsn = "pgsql:host=$host;dbname=$db;port=$port";
|
$pdo = new PDO($dsn, $user, $pass, $opt);
|
||||||
$pdo = new PDO($dsn, $user, $pass, $opt);
|
|
||||||
|
|
||||||
// Error-Message
|
// Creates Error Message
|
||||||
} catch(PDOException $e) {
|
} catch(PDOException $e) {
|
||||||
echo "Error: ".$e->getMessage();
|
echo "Error: ".$e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user