我正在为我的一类使用 mysql 数据库编写一个 php 站点,但我一生都无法弄清楚它有什么问题。我有一个可以在我的机器上本地运行的查询(在与教师服务器上的数据库相同的数据库上)但是当我上传它时,它不起作用。问题是查询返回 0 结果,即使数据库中有应该显示的信息。
function bigAssQuery($whereCondition)
{
$queries[] = 'CREATE TEMPORARY TABLE subAssignments (SELECT ua.assignmentid, ua.assignmentnum, ua.description
FROM Course c JOIN UserAssignment ua ON ua.crn = c.CRN AND ua.term = c.term
WHERE c.CRN = "'.$_SESSION["crnum"].'" AND c.term = "'.$_SESSION["mysem"].'")';
$queries[] = 'CREATE TEMPORARY TABLE subStudents (SELECT s.studentid, s.lastname, s.firstname
FROM Course c JOIN Student s ON s.crn = c.CRN AND s.term = c.term
WHERE c.CRN = "'.$_SESSION["crnum"].'" AND c.term = "'.$_SESSION["mysem"].'")';
$queries[] = 'CREATE TEMPORARY TABLE subRubric(SELECT assignmentid, re.rubricelementid, re.learning_goal_char
FROM RubricElement re JOIN RubricAssignmentRelation rar ON re.rubricelementid = rar.rubricelementid)';
$queries[] = 'CREATE TEMPORARY TABLE subAssignRub(SELECT subAssignments.assignmentid, rubricelementid, learning_goal_char, assignmentnum, description
FROM subRubric JOIN subAssignments ON subAssignments.assignmentid = subRubric.assignmentid)';
$queries[] = 'CREATE TEMPORARY TABLE subAssignRubStud (SELECT *
FROM subAssignRub CROSS JOIN subStudents)';
$queries[] = 'CREATE TEMPORARY TABLE subAssignInstRubStud (SELECT sars.assignmentid, ai.ainstanceid, rubricelementid, learning_goal_char, assignmentnum, description, sars.studentid, lastname, firstname
FROM subAssignRubStud sars LEFT JOIN AssignmentInstance ai ON sars.studentid = ai.studentid AND sars.assignmentid = ai.assignmentid)';
$queries[] = 'CREATE TEMPORARY TABLE subTotal (SELECT assignmentid, siars.ainstanceid, s.ainstanceid As scoreAID, siars.rubricelementid, learning_goal_char, assignmentnum, description, studentid, lastname, firstname, score
FROM subAssignInstRubStud siars LEFT JOIN Score s ON siars.ainstanceid = s.ainstanceid AND siars.rubricelementid = s.rubricelementid
ORDER BY lastname, assignmentid)';
$queries[] = 'SELECT *
FROM subTotal
'.$whereCondition.' Order By lastname, assignmentnum, learning_goal_char';
return($queries);
}
然后当查询数据库时,代码如下所示。. .
$queries = bigAssQuery($whereCondition);
$result = 1;
foreach($queries as $query)
{
$result = $db->query($query);
if(!$result)
{
echo '<script type="text/javascript">
window.onload=function(){ alert("Error: Could not extract course information. Please try again later."); }
</script> ';
exit;
}
}
$num_rows = $result->num_rows;
我向您保证,本地和远程数据库是相同的。我看不出没有结果的原因。我确实测试了一些简单的临时表,以查看服务器是否由于某种原因没有读取这些表,但在我的测试中它们不是问题。我会尝试使用嵌套子查询,但它变得如此复杂,以至于我无法组织它。也许有更好的方法?此外,只是为了澄清查询没有失败,当我知道它们应该返回时,它们只是没有返回任何内容。我为文字墙道歉,但感谢任何帮助。
编辑:我真的不知道问题出在哪个查询上。我知道我可能遗漏了一些重要信息。部分原因在于我缺乏网络经验。我首先在本地进行测试,因为我已经让调试器工作了,但老实说,我不知道如何进行远程调试。我正在使用 netbeans 和 xdebug。如果有人可以建议如何设置远程调试,我可能会想出一些更好的数据。任何的意见都将会有帮助
再次编辑:发现问题。令人尴尬的是,这是数据输入错误;我的一个外键输入错误。感谢大家为我指出正确的方向。