I'm loading files 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 KEY,
`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`)"
I've also tried reading the file into an array and just using an INSERT .. ON DUPLICATE KEY
INSERT INTO $table (`order`,`data`)
VALUES ($parts[0],'$parts[1]')
ON DUPLICATE KEY UPDATE `order` = '$parts[0]'
In both cases if data is the the same in the new and old record but order is different it INSERTs. I expect it to UPDATE if data is the same. I expect my tables not set up properly, but can't see what the problem is. Can anyone tell me why it doesn't UPDATE when data matches?