query("SHOW COLUMNS FROM {$DB}.estimate"); $columns = $columnQuery->fetchAll(PDO::FETCH_COLUMN); // 2. 기본 WHERE 조건 설정 (major_category 필터 적용) $conditions = ["major_category = :whichItem"]; $bindParams = [":whichItem" => $whichItem]; // 3. 검색어가 있는 경우, 전체 컬럼에서 LIKE 검색 적용 if (!empty($search)) { $searchConditions = []; foreach ($columns as $index => $column) { $paramName = ":search" . $index; // 유니크한 바인딩 변수 생성 (:search0, :search1, ...) $searchConditions[] = "$column LIKE $paramName"; $bindParams[$paramName] = "%{$search}%"; } $conditions[] = "(" . implode(" OR ", $searchConditions) . ")"; } // 4. 최종 SQL 쿼리 구성 $sql = "SELECT * FROM {$DB}.estimate WHERE " . implode(" AND ", $conditions) . " AND (is_deleted IS NULL or is_deleted ='0') ORDER BY indate DESC"; $stmh = $pdo->prepare($sql); // 5. 1:1 바인딩 적용 (PHP 7.3 호환) foreach ($bindParams as $key => $val) { $stmh->bindValue($key, $val, PDO::PARAM_STR); } $stmh->execute(); $output_rows = $stmh->fetchAll(PDO::FETCH_ASSOC); // JSON 출력 header('Content-Type: application/json'); echo json_encode($output_rows ?: []); } catch (PDOException $Exception) { header('Content-Type: application/json'); echo json_encode(["error" => $Exception->getMessage()]); exit; } ?>