尝试使用代码点火器批量插入csv文件

时间:2013-12-16 06:07:09

标签: php mysql codeigniter bulkinsert

我正在尝试直接从assets / temp / filename批量插入csv文件到mysql表users_csv_import。

我收到mysql语法错误,我找不到它。

    function bulk_insert_file($filename) {

        $file_location = 'assets/temp/'.$filename;
        $sql = "LOAD DATA INFILE '".$file_location."' INTO TABLE users_csv_import
        TERMINATED BY '\r\n'";

        $this->db->query($sql); 
    }

出现此错误:

Error Number: 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 'TERMINATED BY ' '' at line 2

LOAD DATA INFILE 'assets/temp/new_users_template24.csv' INTO TABLE users_csv_import TERMINATED BY ' '

Filename: C:\Program Files (x86)\Ampps\www\system\database\DB_driver.php

行号:330

1 个答案:

答案 0 :(得分:0)

您在查询语法中出错,您在那里引用了一些引号。应该是:

$sql = "LOAD DATA INFILE '".$file_location."' INTO TABLE users_csv_import
        FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'";