Mysqli bind_param 未设置但仍在执行
Mysqli bind_param not setting but still executing
我尝试了多种不同的格式设置方式,其中 none 行得通。
Mysql 历史显示这是它试图执行的:SELECT * FROM operations WHERE id= ? ORDER BY exectime
这是脚本:
<?php
$sql = "SELECT * FROM operations WHERE id = ? ORDER BY exectime";
if($stmt = mysqli_prepare($link, $sql)){
$stmt -> bind_param("i", $_SESSION["id"]);
if($result = $stmt->execute()){
if(mysqli_stmt_fetch($stmt) > 0) {
while($row = mysqli_stmt_fetch($stmt)) {
echo $row[0];
}
} else {
echo "Empty";
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
mysqli_stmt_close($stmt);
}
?>
更奇怪的是我在登录页面上使用 bind_param 并且工作完全正常。
它甚至没有回应“糟糕!出了点问题。请稍后重试。”;
你把整个事情复杂化了。由于代码太乱,很难准确找到问题所在。您的 while
循环和前面的 if
语句绝对不正确。
保持简单。 Enable mysqli error reporting and then use OOP style and get_result()
方法。
$stmt = $link->prepare("SELECT * FROM operations WHERE id = ? ORDER BY exectime");
$stmt->bind_param("i", $_SESSION["id"]);
$stmt->execute();
$result = $stmt->get_result();
$data = $result->fetch_all(MYSQLI_NUM);
if ($data) {
foreach ($data as $row) {
echo $row[0];
}
} else {
echo "Empty";
}
我尝试了多种不同的格式设置方式,其中 none 行得通。
Mysql 历史显示这是它试图执行的:SELECT * FROM operations WHERE id= ? ORDER BY exectime
这是脚本:
<?php
$sql = "SELECT * FROM operations WHERE id = ? ORDER BY exectime";
if($stmt = mysqli_prepare($link, $sql)){
$stmt -> bind_param("i", $_SESSION["id"]);
if($result = $stmt->execute()){
if(mysqli_stmt_fetch($stmt) > 0) {
while($row = mysqli_stmt_fetch($stmt)) {
echo $row[0];
}
} else {
echo "Empty";
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
mysqli_stmt_close($stmt);
}
?>
更奇怪的是我在登录页面上使用 bind_param 并且工作完全正常。
它甚至没有回应“糟糕!出了点问题。请稍后重试。”;
你把整个事情复杂化了。由于代码太乱,很难准确找到问题所在。您的 while
循环和前面的 if
语句绝对不正确。
保持简单。 Enable mysqli error reporting and then use OOP style and get_result()
方法。
$stmt = $link->prepare("SELECT * FROM operations WHERE id = ? ORDER BY exectime");
$stmt->bind_param("i", $_SESSION["id"]);
$stmt->execute();
$result = $stmt->get_result();
$data = $result->fetch_all(MYSQLI_NUM);
if ($data) {
foreach ($data as $row) {
echo $row[0];
}
} else {
echo "Empty";
}