I try to do INSERT IF NOT EXISTS
So I search for this and I found:How to 'insert if not exists' in MySQL?
So I try to use IGNORE
, this is my table:
CREATE TABLE `users` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255),
`mail` VARCHAR(255),
PRIMARY KEY (`id`)
) CHARACTER SET utf8 COLLATE utf8_general_ci;
And this is my query:
INSERT IGNORE INTO `users` SET `mail` = ?, `name` = ?
But its insert even if exists So I search for that and i found: mySQL INSERT IGNORE doesn't "ignore"
I read there that only with PRIMARY KEY its dosent insert duplicates
So as you can see in my table I have PRIMARY KEY
If the problem is that I need to insert into my query the id field its problem because I dont know what it is when I do the query
So how to insert information to db without creating duplicates ?