<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
header("Content-Type: application/json");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

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

if (isset($_POST['recordjointbar'])) {
    $recordjointbar_jsondata = json_decode($_POST['recordjointbar'], true);
} else {
    $recordjointbar_jsondata = null;
}
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();

try {       
    $pdo->beginTransaction();    
    $sql = "UPDATE {$DB}.{$tablename}  
            SET recordjointbar=? WHERE num=? LIMIT 1";
    $stmh = $pdo->prepare($sql);
    $stmh->bindValue(1, json_encode($recordjointbar_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,                    
    'recordjointbar_jsondata' => $recordjointbar_jsondata,                    
];

echo json_encode($data, JSON_UNESCAPED_UNICODE);
?>
