Initial Commit: Tugas Semua Pertemuan
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
function loadEnv($path) {
|
||||
$env = [];
|
||||
if (!file_exists($path)) return $env;
|
||||
|
||||
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '' || $line[0] === '#') continue;
|
||||
|
||||
$parts = explode('=', $line, 2);
|
||||
if (count($parts) === 2) {
|
||||
$env[trim($parts[0])] = trim(trim($parts[1]), '"\'');
|
||||
}
|
||||
}
|
||||
return $env;
|
||||
}
|
||||
|
||||
$env = loadEnv(__DIR__ . '/.env');
|
||||
|
||||
$conn = mysqli_connect(
|
||||
$env['DB_HOST'] ?? '127.0.0.1',
|
||||
$env['DB_USER'] ?? 'root',
|
||||
$env['DB_PASSWORD'] ?? '',
|
||||
$env['DB_NAME'] ?? 'db_spbu',
|
||||
(int)($env['DB_PORT'] ?? 3306)
|
||||
);
|
||||
|
||||
if (!$conn) {
|
||||
die("Koneksi gagal: " . mysqli_connect_error());
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user