MySQL查询不会在PHP脚本中执行,但在MySQL Workbench中工作正常

时间:2017-03-03 21:49:18

标签: php mysql mysqli

我正在使用Hurl.It进行测试,所以我知道我传递给脚本的值很好,并且接收PHP本身的值不是问题。但是当通过PHP触发时,查询将不会执行,即使我可以在MySQL Workbench中正确执行它。这是代码:

$UserName = $_POST['UserName'];

$getPermissionsQuery = "UPDATE Enrollment_Table.Scenario s, (SELECT p.School_ID, p.School_Name, p.School_Chancellor FROM Enrollment_Table.Schools p INNER JOIN
(SELECT a.User_ID, a.User_Name, b.Permission_ID, b.Permission_School FROM Enrollment_Table.Users a
LEFT JOIN Enrollment_Table.User_Permissions b ON a.User_ID = b.Permission_User_ID WHERE a.User_Name = '$UserName') q ON p.School_ID = q.Permission_School)
t SET s.Enrollment_Change_Scenario = 0, s.Tuition_Increase = 0 WHERE s.Enrollment_School = t.School_Name AND s.Campus = t.School_Chancellor";

$getPermissionsAction = mysqli_query($conn, $getPermissionsQuery);

1 个答案:

答案 0 :(得分:0)

原来我必须使用mysqli_select_db($ conn,$ db)。

这很奇怪,因为我只需要$ conn变量来执行项目中其他地方的其他查询。我在这里使用相同的程序,但由于某些原因这还不够。选择数据库使其有效。