[英]SQL Query returns NULL in PHP but works fine in PHPMyAdmin
運行此代碼:
public function findBooking($start_date, $pitches, $nights, $people, $first_name, $last_name, $email){
$error = false;
$bookings = array();
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (!$this->db_connection->connect_errno) {
if((!$start_date == '') && (!$nights == '')){
$end_date = date('Y-m-d', strtotime($start_date. ' + ' . ($nights-1) . ' days'));
} else {
$end_date = '';
}
$find_booking_sql = "SELECT * FROM booking LEFT JOIN camper ON booking.camper_id = camper.camper_id
WHERE (start_date LIKE '%$start_date%')
AND (end_date LIKE '%$end_date%')
AND (pitches LIKE '%$pitches%')
AND (people LIKE '%$people%')
AND (first_name LIKE '%$first_name%')
AND (last_name LIKE '%$last_name%')
AND (email LIKE '%$email%')
ORDER BY start_date ASC";
$find_booking_result = $this->db_connection->query($find_booking_sql);
if ((!$find_booking_result->num_rows == 0)) {
// Not run
}
} else {
$error = 'No bookings found';
}
}
return array(
'bookings' => $bookings,
'error' => $this->db_connection->error,
'debug' => $find_booking_sql,
'result' => $find_booking_result
);
}
在 PHP 中運行時返回current_field":null,"field_count":null,"lengths":null,"num_rows":null,"type":null
,但如果我從 PHPMyAdmin 運行 SQL,它工作正常。
我檢查過類似的問題,但解決方案不適用於此問題 - 我嘗試刪除 's,並且只有一個查詢正在運行。
示例生成的 SQL:
SELECT *
FROM booking
LEFT JOIN camper ON booking.camper_id = camper.camper_id
WHERE (start_date LIKE '%')
AND (end_date LIKE '%')
AND (pitches LIKE '%')
AND (people LIKE '%')
AND (first_name LIKE '%')
AND (last_name LIKE '%') AND (email LIKE '%')
ORDER BY start_date ASC`
我的錯誤 - 我在實時的空數據庫上運行 PHP 查詢,但在登台數據庫上運行 PHPMyAdmin 查詢。
我切換了數據庫,原始代碼運行良好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.