<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
header("Content-Type: application/json");

$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
$num = isset($_REQUEST['num']) ? $_REQUEST['num'] : '';
$tablename = isset($_REQUEST['tablename']) ? $_REQUEST['tablename'] : '';

include '_request.php';

if (isset($_POST['recordbendingMid'])) {
    $recordbendingMid_jsondata = json_decode($_POST['recordbendingMid'], true);
} else {
    $recordbendingMid_jsondata = null;
}

require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();

try {
    // $update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . substr($update_log, 0, 200) . "&#10";
    $pdo->beginTransaction();
    
    $sql = "UPDATE $DB.$tablename 
            SET recordbendingMid=? WHERE num=? LIMIT 1";

    $stmh = $pdo->prepare($sql);
    $stmh->bindValue(1, json_encode($recordbendingMid_jsondata), PDO::PARAM_STR);          
    $stmh->bindValue(2, $num, PDO::PARAM_STR);

    $stmh->execute();
    $pdo->commit();
    
} catch (PDOException $Exception) {
    error_log("오류: " . $Exception->getMessage());
}

$data = [
    'num' => $num,        
    'is_deleted' => $is_deleted ?? null,
    'recordbendingMid_jsondata' => $recordbendingMid_jsondata
];

echo json_encode($data, JSON_UNESCAPED_UNICODE);
?>
