Inserting external data in database
I have to import some data in my database . And there are some record already exist in table, not all. So what I want to do that:
Run a php script for inserting data in table from input array
Make data_id unique ( not primary key) in mysql table
While inserting via php script if same data_id exist don't stop the execution but skip that record and process next.
something like this I want to do.
But my script stopping execution when data_id is repeated.
can anyone explain how can i handle this.
I don't want to apply check in database that id data_id is already开发者_开发技巧 exist then skip that record else insert because that will make page very slow.
You could use INSERT...ON DUPLICATE KEY UPDATE
or INSERT IGNORE
Check this:
http://dev.mysql.com/doc/refman/5.5/en/insert.html
On duplicate key ignore?
"INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY UPDATE"
Use insert ignore into table (fields) values (values)
This works
精彩评论