简体   繁体   English

加载数据文件问题

[英]load data infile question

I'm currently using LOAD DATA INFILE in my query, but I am not sure how to separate the data 我当前在查询中使用LOAD DATA INFILE,但是我不确定如何分隔数据

The data is in the following format firstname:lastname 数据采用以下格式的名字:姓氏

$this->db->query("LOAD DATA INFILE 'names.txt' 
                  INTO names firstname lastname 
                FIELDS TERMINATED BY ':'");

How would I use this to take the data from the text file and split firstname:lastname to insert firstname into firstname & lastname into lastname? 我将如何使用它从文本文件中获取数据并拆分firstname:lastname以将firstname插入firstname并将lastname插入lastname?

I'm assuming your table name is names . 我假设您的表名是names In which case the query should be: 在这种情况下,查询应为:

"LOAD DATA INFILE 'names.txt' 
    INTO TABLE names
    FIELDS TERMINATED BY ':' 
    (firstname, lastname)"

Then of course you have to execute the statement. 然后,您当然必须执行该语句。

Also take care of newline characters, field enclosure characters and field escape characters, for which you specify [LINES] TERMINATED BY , [FIELDS] ENCLOSED BY and [FIELDS] ESCAPED BY respectively (square brackets meaning that you only specify LINES or FIELDS once). 还要注意换行符,字段包围符和字段转义符,分别为它们指定[LINES] TERMINATED BY[FIELDS] ENCLOSED BY[FIELDS] ESCAPED BY (方括号表示只指定一次LINESFIELDS ) 。

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

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