【发布时间】:2014-08-03 12:00:55
【问题描述】:
我一直在将我的一个 Web 应用程序转换为使用 PostgreSQL 数据库创建具有多个答案的测验到 MySQL 数据库。以下之前在 PostgreSQL 中运行良好的查询在 MySQL 中无法运行。
第一个查询确实被正确插入,但是第二个和第三个根本没有插入。
然而奇怪的是,为两个失败的查询生成了一个序列号。我可以说,因为当我重试插入时,成功的第一个查询每次都会增加 3 个 ID 号。我还在每个查询之前使用了 echo 来检查所有变量是否正确。让我感到困惑的另一件事是我也在将一条记录插入另一个也可以正常工作的表中,它似乎多次插入到同一个表中但不起作用?
帮助克服这个困难将不胜感激!
//answer 1
$answercreatequery = mysqli_query($db_handle, "INSERT INTO answer (answerid, questionid, adescription, afilelocation, iscorrect) VALUES( default, '".$thisquestionid."', '".$adescription1."', '".$afilelocation."', '".$iscorrect1."') ");
//answer 2
$answercreatequery = mysqli_query($db_handle, "INSERT INTO answer (answerid, questionid, adescription, afilelocation, iscorrect) VALUES( default, '".$thisquestionid."', '".$adescription2."', '".$afilelocation."', '".$iscorrect2."') ");
//answer 3
$answercreatequery = mysqli_query($db_handle, "INSERT INTO answer (answerid, questionid, adescription, afilelocation, iscorrect) VALUES( default, '".$thisquestionid."', '".$adescription3."', '".$afilelocation."', '".$iscorrect3."') ");
【问题讨论】: