0
我一直在試圖插入使用此代碼的數據到數據庫中,但一個錯誤出來是這樣的:錯誤的SQL語法與「隨機存取存儲器」
您的SQL錯誤句法;檢查 對應於你的MySQL服務器版本使用 附近「隨機存取存儲器」 -RAM正確的語法手冊 - 「‘DDR1內存’)」在1號線
<?php
$dbhost = 'localhost';
$dbuser = '';
$dbpass = '';
$dbname = 'ticketstatus';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
mysqli_select_db($conn,$dbname);
$fname ="report.csv";
$chk_ext = explode(".",$fname);
if(strtolower($chk_ext[1]) == "csv")
{
$filename = "report.csv";
$handle = fopen($filename, "r");
while (($data = fgetcsv($handle, 100000, ",")) !== FALSE)
{
//print_r($data);
$sql1 = "INSERT into ticket(ticketID,ticketDate,ticketResDate,ticketStatus) values('$data[0]','$data[1]','$data[15]','$data[13]')";
mysqli_query($conn,$sql1) or die(mysqli_error($conn));
$sql2 = "INSERT into enduser(ticketID,endUserID,endUserName,endUserPhone,endUserLoc,endUserState) values('$data[0]','@dummy','$data[2]','$data[3]','$data[4]','$data[5]')";
mysqli_query($conn,$sql2) or die(mysqli_error($conn));
$sql3 = "INSERT into defect(ticketID,defectID,defectCategory,defectBrand,defectModel,defectSerialNo,defectType,defectDesc,defectCauses,defectReplace) values('$data[0]','@dummy','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]','$data[11]','$data[12]','$data[14]')";
mysqli_query($conn,$sql3) or die(mysqli_error($conn));
$sql4 = "INSERT into technician(ticketID,techID,techName,techRemarks) values('$data[0]','@dummy','$data[16]','$data[17]')";
mysqli_query($conn,$sql4) or die(mysqli_error($conn));
$sql5 = "INSERT into status(ticketID,statusID,statusAz,statusAF) values('$data[0]','@dummy','$data[18]','$data[19]')";
mysqli_query($conn,$sql5) or die(mysqli_error($conn));
}
fclose($handle);
echo "Successfully Imported";
}
else
{
echo "Invalid File";
}
?>
哪一部分做我做錯了?
「RANDOM ACCESS MEMORY」-RAM-'中有單引號,因爲它會干擾字符串周圍的單引號,所以需要進行轉義。 [這篇文章](http://stackoverflow.com/questions/9596652/how-to-escape-apostrophe-in-mysql)應該會幫助你 – Val
列出完全失敗的SQL查詢,請 –
@Val,謝謝,我嘗試一下:) – emi