초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
This commit is contained in:
27
eworks/eworksmydb.php
Normal file
27
eworks/eworksmydb.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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());
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user