我有一个新配置的服务器。
我正在尝试在 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/