Solved

LOAD DATA LOCAL INFILE

Posted on 2015-01-19
1
149 Views
Last Modified: 2015-01-21
I found this code which seems to work but I need to make sure it does not add duplicate records and that it updates existing records with like key values.

Will the code below Insert only or will it Replace the records with same primary key.
If not whats the mysql statement to Replace when doing a LOAD DATA INLINE??


========== IMPORT RECORDS INTO MYSQL FROM CSV FILE  ===================



    $csvfile1 = 'property_a.csv';
   
    $sql = mysql_query("LOAD DATA LOCAL INFILE '$csvfile1' INTO TABLE table_a FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES
TERMINATED BY '\n' IGNORE 1 LINES") or die (mysql_error());
    if (!$sql) {        // problem
        echo mysql_error() ."<br>";
    } else {
        echo "success!";

        }
0
Comment
Question by:leadcodev
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40559193
just apply REPLACE:
http://dev.mysql.com/doc/refman/5.1/en/load-data.html
he REPLACE and IGNORE keywords control handling of input rows that duplicate existing rows on unique key values:

    If you specify REPLACE, input rows replace existing rows. In other words, rows that have the same value for a primary key or unique index as an existing row. See Section 13.2.7, “REPLACE Syntax”. 

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question