초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
This commit is contained in:
117
lot/insert.php
Normal file
117
lot/insert.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
||||
|
||||
$tablename = isset($_REQUEST['tablename']) ? $_REQUEST['tablename'] : '';
|
||||
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
|
||||
|
||||
header("Content-Type: application/json"); // JSON 콘텐츠 유형 설정
|
||||
|
||||
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
||||
$pdo = db_connect();
|
||||
|
||||
include "_request.php";
|
||||
|
||||
$search_tag = $lot_number . ' ' .
|
||||
$reg_date . ' ' .
|
||||
$author . ' ' .
|
||||
$prod . ' ' .
|
||||
$spec . ' ' .
|
||||
$slength . ' ' .
|
||||
$surang . ' ' .
|
||||
$rawLot . ' ' .
|
||||
$fabric_lot . ' ' .
|
||||
$remark . ' ' ;
|
||||
|
||||
if ($mode == "modify") {
|
||||
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . $update_log . "
";
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
// SQL 쿼리 생성 (업데이트)
|
||||
$sql = "UPDATE " . $DB . "." . $tablename . " SET ";
|
||||
$sql .= "reg_date = ?, lot_number = ?, author = ?, remark = ?, update_log = ?, search_tag = ?, prod = ?, spec = ?, slength = ?, surang = ?, rawLot=?, fabric_lot=? ";
|
||||
$sql .= "WHERE num = ? LIMIT 1"; // num이 일치하는 하나의 레코드만 업데이트
|
||||
|
||||
$stmh = $pdo->prepare($sql);
|
||||
|
||||
// 변수 바인딩
|
||||
$stmh->bindValue(1, $reg_date, PDO::PARAM_STR);
|
||||
$stmh->bindValue(2, $lot_number, PDO::PARAM_STR);
|
||||
$stmh->bindValue(3, $author, PDO::PARAM_STR);
|
||||
$stmh->bindValue(4, $remark, PDO::PARAM_STR);
|
||||
$stmh->bindValue(5, $update_log, PDO::PARAM_STR);
|
||||
$stmh->bindValue(6, $search_tag, PDO::PARAM_STR);
|
||||
$stmh->bindValue(7, $prod, PDO::PARAM_STR);
|
||||
$stmh->bindValue(8, $spec, PDO::PARAM_STR);
|
||||
$stmh->bindValue(9, $slength, PDO::PARAM_STR);
|
||||
$stmh->bindValue(10, (int)str_replace(',', '', $surang), PDO::PARAM_INT);
|
||||
$stmh->bindValue(11, $rawLot, PDO::PARAM_STR);
|
||||
$stmh->bindValue(12, $fabric_lot, PDO::PARAM_STR);
|
||||
$stmh->bindValue(13, $num, PDO::PARAM_INT);
|
||||
|
||||
// 실행
|
||||
$stmh->execute();
|
||||
$pdo->commit();
|
||||
} catch (PDOException $Exception) {
|
||||
$pdo->rollBack();
|
||||
print "오류: " . $Exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
else if ($mode == "insert" || $mode == '' || $mode == null) {
|
||||
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . $update_log . "
";
|
||||
// 데이터 삽입
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// SQL 쿼리 생성 (삽입)
|
||||
$sql = "INSERT INTO " . $DB . "." . $tablename . " (";
|
||||
$sql .= "reg_date, lot_number, author, remark, update_log, search_tag, prod, spec, slength, surang, rawLot, fabric_lot ";
|
||||
$sql .= ") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
$stmh = $pdo->prepare($sql);
|
||||
|
||||
// 변수 바인딩
|
||||
$stmh->bindValue(1, $reg_date, PDO::PARAM_STR);
|
||||
$stmh->bindValue(2, $lot_number, PDO::PARAM_STR);
|
||||
$stmh->bindValue(3, $author, PDO::PARAM_STR);
|
||||
$stmh->bindValue(4, $remark, PDO::PARAM_STR);
|
||||
$stmh->bindValue(5, $update_log, PDO::PARAM_STR);
|
||||
$stmh->bindValue(6, $search_tag, PDO::PARAM_STR);
|
||||
$stmh->bindValue(7, $prod, PDO::PARAM_STR);
|
||||
$stmh->bindValue(8, $spec, PDO::PARAM_STR);
|
||||
$stmh->bindValue(9, $slength, PDO::PARAM_STR);
|
||||
$stmh->bindValue(10, (int)str_replace(',', '', $surang), PDO::PARAM_INT);
|
||||
$stmh->bindValue(11, $rawLot, PDO::PARAM_STR);
|
||||
$stmh->bindValue(12, $fabric_lot, PDO::PARAM_STR);
|
||||
|
||||
// 실행
|
||||
$stmh->execute();
|
||||
$pdo->commit();
|
||||
} catch (PDOException $Exception) {
|
||||
$pdo->rollBack();
|
||||
print "오류: " . $Exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
else if ($mode == "delete") { // 데이터 삭제
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
$sql = "UPDATE " . $DB . "." . $tablename . " SET is_deleted=1 WHERE num = ?";
|
||||
$stmh = $pdo->prepare($sql);
|
||||
$stmh->bindValue(1, $num, PDO::PARAM_INT);
|
||||
$stmh->execute();
|
||||
$pdo->commit();
|
||||
} catch (PDOException $ex) {
|
||||
$pdo->rollBack();
|
||||
print "오류: ".$ex->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'num' => $num,
|
||||
'mode' => $mode
|
||||
];
|
||||
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user