SQL 쿼리에 ORDER 및 LIMIT 포함 문제가 있습니다.ORDER, LIMIT 및 sprintf를 사용하여 쿼리
$STH_1 = $DBH_R->query("SELECT table_name
FROM information_schema.tables
WHERE table_name
LIKE 'v_c_ei\_9%'
");
$stmts_1 = array();
//echo "date = ". $date."<br>"; // $date is today date
$date_60 = date('Y-m-d', strtotime('-60 day', strtotime($date))); // $date_60 = today - 60 days
while (($row_1 = $STH_1 -> fetch_assoc()) !== null){
$table_name = $row_1['table_name'];
$stmts_1[] = sprintf("SELECT *
FROM $table_name
WHERE (date_time >= '$date_60') AND (ei_code = '1117')
");
}
// at this place I need help, I think. I have few data from every query but I want to reduce the number of solutions to 1 per table
$stmt_1 = implode("\nUNION\n", $stmts_1);
$stmt_1 .= "\nORDER BY date_time ASC";
$STH_5_2 = $DBH_R->query($stmt_1);
while (($row_5_2 = $STH_5_2 -> fetch_assoc()) !== null){
위의 스크립트가 정상적으로 작동합니다. 하지만 데이터 수를 제한하고 싶습니다 (모든 테이블에서 마지막으로 필요합니다). 나는 sprintf 쿼리에서
ORDER BY date_time DESC LIMIT 0,1
을 통해 시도하지만 작동하지 않으려 고합니다. ORDER 요법을 추가 할 때. 나는 대답을 가지고있다
Fatal error: Call to a member function fetch_assoc() on a non-object in "while (($row_5_2 ..."
누구든지 도움을받을 수 있습니까?
sprintf 쿼리를 통해 코드를 시도 할 때 코드의 모양이 정확히 어떻게 나타 납니까? mysql에서 오류를 확인 했습니까? –
@MarkByers 그가 mysqli를 사용하는 것처럼 보이지는 않을 것입니다. 'echo $ DBH_R-> error; 시도하십시오. –