问题
I have the simple code shown below. After it has run once, it inserts the results into MySQL database twice. It is working fine in all browsers (IE, Chrome, and Safari) except Firefox.
I am using symfony php framework and propel as the ORM.
$con = Propel::getConnection();
$sql = "select * from tmp where user_id =$userid";
$stmt = $con->prepare($sql);
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$insert_sql = "INSERT IGNORE into library(xxx,xxx) VALUES('xyz','xys')";
$insert_stmt = $con->prepare($insert_sql) ;
$insert_stmt->execute();
}
回答1:
Most of time it's being a consequence of unwise mod_rewrite usage, making some file act as a 404 error handler.
Thus, if some resource not found, such a file being called and executed.
Check HTTP headers when calling your page and see what additional requests being made.
回答2:
The problem is deeper.I am not a php developer, but I can understand the problem is the design. Ideally I think your client is making multiple request to your server and each request is inserting a record in the system before checking if the record already exists.
来源:https://stackoverflow.com/questions/5609713/mysql-inserting-records-twice-in-database