使用php中的文本文件将数据加载到mysql表中的特定列中

时间:2013-04-11 06:20:43

标签: php mysql

这是我的代码

$query3="LOAD DATA INFILE 
        'C:/xampp/htdocs/schoolonweb/trainee/views/sliptest/sliptestuploads/$filename' 
        INTO TABLE $sliptesttable 
        (SchoolId,ClassId,SectionId,SubjectId,NewSubjectId,
        SlipTestId,StudentId,Mark) 
        FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' ";

我收到以下错误

  

您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在第1行'FIELDS TERMINATED BY','LINES TERMINATED BY''附近使用正确的语法

有人可以找到错误的位置吗?

2 个答案:

答案 0 :(得分:0)

语法不正确。试试这个 -

LOAD DATA INFILE 
  'C:/xampp/htdocs/schoolonweb/trainee/views/sliptest/sliptestuploads/$filename' 
  INTO TABLE $sliptesttable 
  FIELDS TERMINATED BY ','
  LINES TERMINATED BY '\n'
  (SchoolId,ClassId,SectionId,SubjectId,NewSubjectId, SlipTestId,StudentId,Mark) 

答案 1 :(得分:0)

我认为字段声明必须在声明终止的字段之后:

$query3="LOAD DATA INFILE 
    'C:/xampp/htdocs/schoolonweb/trainee/views/sliptest/sliptestuploads/$filename' 
    INTO TABLE $sliptesttable 
    FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
     (SchoolId,ClassId,SectionId,SubjectId,NewSubjectId,
             SlipTestId,StudentId,Mark) ";
MySQL中的

以这种方式工作documentation