我有这个脚本来连接我的数据库,使用它时出现错误 500。
我试图追踪错误在哪里,我认为它在这一行:while ($row = $stmt->fetch_assoc())
但是我查看了示例,这也是我的。
这是我的代码,感谢您的帮助:
<?php
$mysqli = new mysqli(*MY DB DETAILS*);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sql = "SELECT * FROM comments WHERE workout_name =? AND user =?";
$stmt = $mysqli->prepare($sql) or trigger_error($mysqli->error."[$sql]");
$stmt->bind_param('ss', $workout_name, $user);
$workout_name = $_GET['workout_name'];
$user = $_GET['user'];
$stmt->execute();
if ($stmt)
{
while ($row = $stmt->fetch_assoc())
{
$response["name"] = $row["workout_name"];
echo json_encode($response);
}
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
}
else
{
$response["success"] = 2;
// echoing JSON response
echo json_encode($response);
}
?>
更新:
我不得不改变$row = $stmt->fetch_assoc()
如此处所述: