초기 커밋: 5130 레거시 시스템

- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경
- DB 연결 하드코딩 → .env 기반으로 변경
- MySQL strict mode DATE 오류 수정
This commit is contained in:
2025-12-10 20:14:31 +09:00
commit aca1767eb9
6728 changed files with 1863265 additions and 0 deletions

45
lib/func.php Normal file
View File

@@ -0,0 +1,45 @@
<?php
session_start();
?>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="./css/common.css">
<link rel="stylesheet" type="text/css" href="./css/func.css">
</head>
<?php
function latest_article($table,$loop,$char_limit)
{
require_once("../lib/mydb.php");
$pdo=db_connect();
try{
$sql="select * from chandj.$table order by num desc limit $loop";
$stmh=$pdo->query($sql);
While($row=$stmh->fetch(PDO::FETCH_ASSOC))
{
$num=$row["num"];
$len_subject=strlen($row["subject"]);
$subject=$row["subject"];
if($len_subject>$char_limit)
{
$subject=mb_substr($row["subject"],0,$char_limit,'utf-8');
$subject=$subject . "..."; // 글자수가 초과하면 ...으로 표기됨
}
$regist_day=substr($row["regist_day"],0,10);
$page=1;
echo("<div class='col1'> <a href='./$table/view.php?num=$num&page=$page'>$subject</a>
</div><div class='col2'>$regist_day</div>
<div class='clear'></div>");
}
} catch (PDOException $Exception) {
print "오류: ". $Exception->getMessage();
}
}
?>

21
lib/helper.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
function href($url)
{
print "
<script>
location.href = '$url';
</script>
";
}
function alert($msg)
{
print "
<script>
alert('$msg');
</script>
";
}
?>

35
lib/mydb.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
// .env 파일 로드
function loadEnv() {
$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);
}
}
}
}
function db_connect(){ //DB연결을 함수로 정의
loadEnv();
$db_host = $_ENV['DB_HOST'] ?? 'localhost';
$db_name = $_ENV['DB_NAME'] ?? 'chandj';
$db_user = $_ENV['DB_USER'] ?? 'chandj';
$db_pass = $_ENV['DB_PASS'] ?? '';
$dsn = "mysql:host=".$db_host.";dbname=".$db_name.";charset=utf8";
try {
$pdo = new PDO($dsn,$db_user,$db_pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,FALSE);
} catch (PDOException $Exception) {
die('오류:'.$Exception->getMessage());
}
return $pdo;
}
?>