27 lines
827 B
PHP
27 lines
827 B
PHP
|
|
<?php
|
||
|
|
// .env 파일 로드
|
||
|
|
$envFile = $_SERVER['DOCUMENT_ROOT'] . '/.env';
|
||
|
|
if (file_exists($envFile)) {
|
||
|
|
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||
|
|
foreach ($lines as $line) {
|
||
|
|
if (strpos($line, '=') !== false && strpos($line, '#') !== 0) {
|
||
|
|
list($key, $value) = explode('=', $line, 2);
|
||
|
|
$_ENV[trim($key)] = trim($value);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 데이터베이스 연결 정보
|
||
|
|
$host = $_ENV['DB_HOST'] ?? 'localhost';
|
||
|
|
$dbname = $_ENV['DB_NAME'] ?? 'chandj';
|
||
|
|
$username = $_ENV['DB_USER'] ?? 'chandj';
|
||
|
|
$password = $_ENV['DB_PASS'] ?? '';
|
||
|
|
|
||
|
|
// MySQL 데이터베이스 연결
|
||
|
|
$conn = mysqli_connect($host, $username, $password, $dbname);
|
||
|
|
|
||
|
|
// MySQL 연결 오류 발생 시 스크립트 종료
|
||
|
|
if (mysqli_connect_errno()) {
|
||
|
|
die("Failed to connect to MySQL: " . mysqli_connect_error());
|
||
|
|
}
|
||
|
|
?>
|