Skip to content
Advertisement

PHP MySQL Insert Ignore Inserting Too Much Data

I have a traffic exchange and every time a site is viewed I want it to insert in to a table which looks like:

-user
-site

The user is default of 1 and I don’t insert in to it because I thought for an INSERT IGNORE you need a column that stays in the same.

My current query:

$db->Query("INSERT IGNORE INTO `surfed_site` (site) VALUES('".$sit['id']."')");

I have around 85 people online but in a 1 second refresh it goes from having 0 in the table to 750 which is impossible because a user has to view a site for 20seconds before it inserts.

I think my INSERT IGNORE isn’t working, would anybody be able to guide me to see what I’m doing wrong?

Advertisement

Answer

Are you shure that site is a primary key ?

In order to get INSERT IGNORE working you must declare the inserted value as primary / uniue key

If you use the IGNORE keyword, errors that occur while executing the INSERT statement are treated as warnings instead. For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row still is not inserted, but no error is issued.

http://dev.mysql.com/doc/refman/5.5/en/insert.html

Add Primary Key if not existing with:

ALTER TABLE surfed_site ADD PRIMARY KEY (site);
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement