mysql在数据库中插入记录两次
我有如下所示的简单代码。运行一次后,会将结果插入MySQL数据库两次。 它在除 Firefox 之外的所有浏览器(IE、Chrome 和 Safari)中都能正常工作。
我使用 symfony php 框架和 propel 作为 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();
}
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大多数时候,这是不明智的 mod_rewrite 使用的结果,使某些文件充当 404 错误处理程序。
因此,如果找不到某些资源,则会调用并执行此类文件。
调用页面时检查 HTTP 标头并查看发出了哪些其他请求。
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.
问题更深层次。我不是 php 开发人员,但我可以理解问题在于设计。理想情况下,我认为您的客户端正在向您的服务器发出多个请求,并且每个请求都会在检查记录是否已存在之前在系统中插入一条记录。
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.