简体   繁体   English

MySQL插入语句执行多次并一次插入多个记录

[英]MySQL insert statement is executing multiple times and inserting multiple records at a time

I have a newly configured Server. 我有一个新配置的服务器。

I am trying simple insert statement in MYSQL. 我正在尝试在MySQL中使用简单的插入语句。

My code is like below 我的代码如下

 $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);

After executing above insert statement If i look into the table, multiple rows are inserted. 执行完上述插入语句后,如果我查看表,则会插入多行。 But the script is run only once. 但是该脚本仅运行一次。

I verify i also put a field in that table with type timestamp ( CURRENT_TIMESTAMP ) which will show the current timestamp value and here this is same for multiple records after that insert statement executed. 我确认我还在该表中放置了一个时间戳类型为CURRENT_TIMESTAMP的字段,该字段将显示当前时间戳值,并且在执行插入语句后,对于多个记录而言,这也是相同的。

Updated: 更新:

Find below for the entire function 在下面找到整个功能

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;
        }

i am using amfphp to write service class which has this function and the front-end is Flex app. 我正在使用amfphp编写具有此功能的服务类,前端是Flex应用程序。

As i was saying this entire app was working fine on another server but recently it was moved to AWS server . 正如我所说的那样,整个应用程序在另一台服务器上都可以正常工作,但是最近它已移至AWS服务器上

As the code is above there is no way that multiple rows can be inserted unless: 由于上面的代码无法插入多行,除非:

  • The script is called multiple times. 该脚本被多次调用。 You could verify this by using firebug or fiddler to monitor the requests in your browser. 您可以通过使用Firebug或Fiddler来监视浏览器中的请求来验证这一点。
  • There is a trigger that is causing the duplication. 有一个触发器导致重复。

Additionally, refreshing the page multiple times would also cause the multiple inserts. 此外,刷新页面多次也会导致多次插入。

It would help to have more code in order to see if there is an issue somewhere else. 拥有更多代码以查看其他地方是否有问题将有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM