Я пытаюсь импортировать данные csv в mysql, используя PDO и LOAD DATA INFILE (я также попробовал LOAD DATA LOCAL INFILE), но я продолжаю получать синтаксическую ошибку, и я понятия не имею, почему. Имена файлов и таблиц кажутся правильными.
вот функция import (), которую я использую –
function import() { $this->db = mydb::getConnection(); // set the column names for the selected journal table if ($this->table = "bsp_journals") { $columns = "category, discipline, subject, sourcetype, issn, publicationname, indabstart, indabstop, fulltextstart, fulltextstop, fulltextdelay, peerreviewed"; } try { $sql = "LOAD DATA LOCAL INFILE '$this->file' INTO TABLE '$this->table' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\\n' OPTIONALLY ENCLOSED BY '\"' ($columns)"; $statement = $this->db->prepare($sql); $statement->execute(); $this->return = $this->files['filename']['tmp_name']; } catch (PDOException $ex) { //throw $ex; $this->return = $ex->getMessage() . "<br /></br />" . $sql . "<br /></br />File Name = " . $this->file; } return $this->return; }
ниже – сообщение, которое я получаю, включая сообщение об ошибке mysql и запрос SQL
- import result : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''bsp_journals' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' ' at line 2 LOAD DATA LOCAL INFILE 'files/buh-journals.csv' INTO TABLE 'bsp_journals' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' OPTIONALLY ENCLOSED BY '"' (category, discipline, subject, sourcetype, issn, publicationname, indabstart, indabstop, fulltextstart, fulltextstop, fulltextdelay, peerreviewed) File Name = files/buh-journals.csv