views:

79

answers:

1

I'm loading a file into a table with php. I create a table like this:

CREATE TABLE IF NOT EXISTS $table (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`order` INT DEFAULT 0,
`data` VARCHAR(200) UNIQUE,
`cur_timestamp` TIMESTAMP DEFAULT NOW())";

And fill it from a text file like this:

LOAD DATA LOCAL 
INFILE '".$file ."' REPLACE 
INTO TABLE $table 
FIELDS TERMINATED BY '^' 
(`order`,`data`)";

Even though I'm using REPLACE and data is UNIQUE it creates duplicate records unless order and data are both the same in the record. Can someone suggest where I'm going wrong? I only want it to replace records based on matches to data. I've read the documentation over and over, this looks right to me.

A: 

I thought making making data KEY would do it, but it still inserts if order is different

CREATE TABLE IF NOT EXISTS $table (
`id` INT AUTO_INCREMENT KEY,
`order` INT DEFAULT 0,
`data` VARCHAR(200) UNIQUE KEY,
`cur_timestamp` TIMESTAMP DEFAULT NOW())";