开发者

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:

  1. Run a php script for inserting data in table from input array

  2. Make data_id unique ( not primary key) in mysql table

  3. 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜