Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

LOAD DATA LOCAL INFILE

Posted on 2015-01-19
1
154 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 143

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
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.

809 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