我用這個SQL查詢之間的時間間隔來獲取數據如何在PHP中傳遞sql中的變量?
$start_time = $_POST['i_date'].' 07:00:00';
$end_time = $_POST['i_date'].' 14:00:00';
/*echo $start_time;
die();*/
$sql = 'select * from datetime where code = 1001 and time between '.$start_time.' and '.$end_time;
但我得到以下錯誤信息: 查詢無效:您的SQL語法錯誤;請檢查與您的MySQL服務器版本對應的手冊,以便在第1行'07:00:00和2015-09-09 14:00:00'使用正確的語法。
'... 07:00:00和2015-09-09 14:00:00' - >'... 07:00:00'和'2015-09-09 14:00:00' –
學習使用準備好的語句並綁定變量,那麼你不需要記住引用值 –