简体   繁体   English

将csv文件导入mysql

[英]importing csv file to mysql

I'm using MySQL with php. 我正在使用MySQL与PHP。 Through a php script i'm trying to import a csv file with the following query 通过PHP脚本我试图导入一个csv文件与以下查询

    LOAD DATA LOCAL INFILE '$file'
    INTO TABLE userstable
    FIELDS TERMINATED BY ','
    LINES TERMINATED BY '\n' IGNORE 1 LINES (name, univ, mobile);

I'm successfully able to import the file in to the database tables but i'm able to see hidden formatting symbols (as in word, powerpoint, etc..) in all the cells under the last column ie mobile. 我已成功将文件导入数据库表,但我能够在最后一列(即移动)下的所有单元格中看到隐藏的格式符号(如word,powerpoint等)。

How to avoid those from inserting in the table 如何避免插入表中

Could be DOS line endings. 可能是DOS行结尾。 Try it with 尝试一下

  LINES TERMINATED BY '\r\n'

instead. 代替。

I think you're going to have to use regular expressions to filter the data before it is saved. 我认为你必须使用正则表达式来过滤保存之前的数据。 If I remember correctly, most of that formatting is standardized, so it should be easy to find and eliminate before adding it to your dB. 如果我没记错的话,大多数格式都是标准化的,所以在将它添加到dB之前应该很容易找到并消除。 - lee - 李

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM