当前位置: 动力学知识库 > 问答 > 编程问答 >

php - 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

分享给朋友:
您可能感兴趣的文章:
随机阅读: