我想填充一个数据库。下面的代码在循环中执行以填充一些相关的表。当循环运行 17 次时,“pubmedarticle”和“pubmedarticle_belongsto_user”表将填充 17 条记录。然而,“抽象”表填充了 10 条记录,而其他表填充了 16 条记录!运行循环没有限制,它运行了 17 次,循环后所有表都应包含 17 条记录。我找不到为什么在插入数据库时缺少一些内容。我很欣赏你的想法。
以下是主键:
pubmedarticle: pubmedArticleId
pubmedarticle_belongsto_user: userId, pubmedArticleId
article: articleId, pubmedArticleId
abstract: abstractId, articleId , pubmedArticleId
pagination: paginationId, articleId, pubmedArticleId
我检查了 mysqli_error 并且收到了 6 次这个结果(缺少 6 个!): 错误描述:您的 SQL 语法有错误;查看与您的 MySQL 服务器版本相对应的手册,了解正确的语法,以使用 near 迄今为止最全面的地震灾害演习。第 1 行的半结构化面试
这是代码:
mysqli_query($con,"INSERT INTO pubmedarticle (pubmedId) VALUES ('$pmid')");
//------------
$result_last_row = mysqli_query($con, "SELECT pubmedArticleId from pubmedarticle order by pubmedArticleId desc limit 1");
while($row2 = mysqli_fetch_array($result_last_row)) {
$last_userID = $row2['pubmedArticleId'];
}
mysqli_query($con,"INSERT INTO pubmedarticle_belongsto_user (userId, pubmedArticleId) VALUES ('$userId','$last_userID')");
//------------
mysqli_query($con,"INSERT INTO article (pubmedArticleId, articleTitle, articleDate) VALUES ('$last_userID', '$title', '$year_final')");
$result_last_row2 = mysqli_query($con, "SELECT articleId from article order by articleId desc limit 1");
while($row3 = mysqli_fetch_array($result_last_row2)) {
$last_userID_article = $row3['articleId'];
}
if (!mysqli_query($con,"INSERT INTO abstract (articleId, pubmedArticleId, abstractText) VALUES ('$last_userID_article','$last_userID', '$abstract')")){
echo("Error description: " . mysqli_error($con));
echo "</br>";
}
mysqli_query($con,"INSERT INTO pagination (articleId, pubmedArticleId, medlinePgn) VALUES ('$last_userID_article','$last_userID', '$medlinepgn')");
mysqli_query($con,"INSERT INTO publicationtype (articleId, pubmedArticleId, publicationType) VALUES ('$last_userID_article','$last_userID', '$publicationtype')");
mysqli_query($con,"INSERT INTO journal (articleId, pubmedArticleId, issn, journalIssuePubDate, volume, issue, journalTitle, isoAbbreviation)
VALUES ('$last_userID_article','$last_userID', '$issn', '$year_final','$volume', '$issue', '$journalTitle', '$isoAbbreviation')");