setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); // 이 스크립트의 메모리 제한 증가 ini_set('memory_limit', '256M'); $sql = "SELECT * FROM " . $DB . "." . $tablename; try { $stmh = $pdo->prepare($sql); $stmh->execute(); $rows = $stmh->fetchAll(PDO::FETCH_ASSOC); $pdo->beginTransaction(); foreach ($rows as $row) { // 1차부터 6차까지의 데이터를 배열로 구성 $accountListData = []; for ($i = 1; $i <= 6; $i++) { // 'col4' 또는 'col6' 중 하나라도 값이 있을 때만 행을 추가 if (!empty($row["bill$i"]) || !empty($row["deposit$i"])) { $data = [ 'col1' => ($row["bill_issueDate$i"] === '0000-00-00') ? '' : ($row["bill_issueDate$i"] ?? ''), 'col2' => $row["bill{$i}_supply"] ?? '', 'col3' => $row["bill{$i}_vat"] ?? '', 'col5' => ($row["depositdate$i"] === '0000-00-00') ? '' : ($row["depositdate$i"] ?? '') ]; if (!empty($row["bill$i"])) { $data['col4'] = $row["bill$i"]; } if (!empty($row["deposit$i"])) { $data['col6'] = $row["deposit$i"]; } $accountListData[] = $data; } } // JSON으로 변환 $accountListJson = json_encode($accountListData, JSON_UNESCAPED_UNICODE); // 데이터베이스 업데이트 $updateSql = "UPDATE $DB.$tablename SET accountList = :accountList WHERE num = :num"; $updateStmh = $pdo->prepare($updateSql); $updateStmh->bindValue(':accountList', $accountListJson, PDO::PARAM_STR); $updateStmh->bindValue(':num', $row['num'], PDO::PARAM_INT); $updateStmh->execute(); } $pdo->commit(); echo "모든 레코드의 accountList가 성공적으로 업데이트되었습니다."; } catch (PDOException $Exception) { $pdo->rollBack(); echo "오류: " . $Exception->getMessage(); } ?>