php - MySQL插入语句执行多次并一次插入多条记录

标签 php mysql amfphp

我有一个新配置的服务器。

我正在尝试在 MYSQL 中执行简单的插入语句。

我的代码如下

 $stmt=mysqli_prepare($this->db->initCon(),
 "INSERT INTO user_exam_taken
 (user_exam_id, completed, last_question_id, mode, question_ids, time_elapsed, score) 
 VALUES ('".$request->user_exam_id."', '".$request->completed."', 
 '".$request->last_question_id."', '".$request->mode."', '".$request->question_ids."',
 '".$request->time_elapsed."', '".$request->score."');");  
 // This is the entire insert and its not in a loop
 mysqli_stmt_execute($stmt);

执行上述插入语句后,如果我查看表,会插入多行。但该脚本仅运行一次。

我验证我还在该表中放置了一个时间戳类型 (CURRENT_TIMESTAMP) 的字段,该字段将显示当前时间戳值,并且在执行插入语句后,这对于多个记录来说是相同的。

更新:

在下面查找整个函数

function addExamResults(Exam_ResultVO $request)
        {
            $stmt=mysqli_prepare($this->db->initCon(),"INSERT INTO `user_exam_taken` (`user_exam_id`, `completed`, `last_question_id`, `mode`, `question_ids`, `time_elapsed`, `score`) VALUES ('".$request->user_exam_id."', '".$request->completed."', '".$request->last_question_id."', '".$request->mode."', '".$request->question_ids."', '".$request->time_elapsed."', '".$request->score."');");
            mysqli_stmt_execute($stmt);
            $request->id=$this->db->getLastInsertId();
            return $request;
        }

我正在使用amfphp编写具有此功能的服务类,前端是Flex应用程序。

正如我所说,整个应用程序在另一台服务器上运行良好,但最近它被移至AWS 服务器

最佳答案

由于上面的代码,无法插入多行,除非:

  • 该脚本被调用多次。您可以使用 firebug 或 fiddler 来验证这一点监控浏览器中的请求。
  • 存在导致重复的触发器。

另外,多次刷新页面也会导致多次插入。

拥有更多代码将有助于查看其他地方是否存在问题。

关于php - MySQL插入语句执行多次并一次插入多条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18867307/

相关文章:

C# Winforms 控件 - DataGridView - 更新数据库

php - 跨 session 的用户特定内容建议 [MySQL/Web]

flash - 我可以重新使用 Actionscript 3 NetConnection 吗?

php - 模糊或隐藏 PHP-AS3 项目中使用的路径的最简单方法是什么

php - Codeigniter 多数据库连接速度慢

php - 无需重启即可清除 Laravel 队列缓存

php - 在 Laravel MongoDB 中显示 EmbedsMany 数据

php - 是否可以在单个查询中选择表 1 中的所有行和表 2 中的每一行元数据?

mysql - 减去 MySQL 中 2 个特定行的值

propel - 在重构代码之前你会考虑什么?