1
我正在使用codeigniter。嘗試將csv文件加載到數據庫中。 $path = 'C:/xampp/htdocs/CodeIgniter-3.0.6/';
您的SQL語法有錯誤:MariaDB服務器+ codeigniter + LOAD DATA INFILE
錯誤:
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Institution ID Code,Acquiring Institution Name,Service Indicator,Local Point of ' at line 5
LOAD DATA INFILE "C:/xampp/htdocs/CodeIgniter-3.0.6/fichier/test3.csv" INTO TABLE atm_location FIELDS TERMINATED BY ";" LINES TERMINATED BY "\n" IGNORE 0 LINES (Acquiring Institution ID Code,Acquiring Institution Name,Service Indicator,Local Point of Service ID,Country Code,Administrative Region, Tourist Area,City/Town/Locality,Postal Code,Address,Location Name,Type of Location,Type of Access,Opening Hours,Opening Days,Card Programm Indicator,Opening Date,GPS Latitude,GPS Longitude)
Filename: C:/xampp/htdocs/CodeIgniter-3.0.6/system/database/DB_driver.php
Line Number: 691
這工作:
$query = $this->db->query('LOAD DATA INFILE "'.$path.'fichier/test3.csv" INTO TABLE atm_location FIELDS TERMINATED BY ";"');
該好好嘗試一下工作(給上述錯誤):
$query = $this->db->query('
LOAD DATA INFILE "'.$path.'fichier/test3.csv"
INTO TABLE atm_location FIELDS TERMINATED BY ";"
LINES TERMINATED BY "\n"
IGNORE 0 LINES
(Acquiring Institution ID Code,Acquiring Institution Name,Service Indicator,Local Point of Service ID,Country Code,Administrative Region, Tourist Area,City/Town/Locality,Postal Code,Address,Location Name,Type of Location,Type of Access,Opening Hours,Opening Days,Card Programm Indicator,Opening Date,GPS Latitude,GPS Longitude)');
沒有列缺。 csv文件沒有列名。數據庫的列名稱與此處寫入的名稱相同。我正在使用xampp來處理localhost。
謝謝,我不知道空間是一個問題,我不知道\'的存在。 \'和'有什麼區別?他們做同樣的事情,但允許重疊? – Firefly
Bactick是mysql中標識符(表名,列等)的引號字符。單引號和雙引號用於引用字符串,字符和時間的字符串表示形式的值,例如 – Ray
您可以啓用'ANSI_QUOTES',這將允許雙引號也是標識符引號,但不要這樣做,只需粘貼反推。它使它不那麼容易混淆,因爲你總是知道被提醒的名字是一個標識符。此外,您不能保證您的查詢將在系統上使用,並且關閉了ansi報價。 – Ray