遍历mysqli预准备语句并输出结果的步骤如下:
$connection = mysqli_connect("localhost", "username", "password", "database");
if (!$connection) {
die("连接数据库失败:" . mysqli_connect_error());
}
$query = "SELECT * FROM table WHERE column = ?";
$statement = mysqli_prepare($connection, $query);
if (!$statement) {
die("预准备语句准备失败:" . mysqli_error($connection));
}
$value = 123;
mysqli_stmt_bind_param($statement, "i", $value);
if (!mysqli_stmt_execute($statement)) {
die("执行预准备语句失败:" . mysqli_stmt_error($statement));
}
$result = mysqli_stmt_get_result($statement);
if (!$result) {
die("获取结果集失败:" . mysqli_stmt_error($statement));
}
while ($row = mysqli_fetch_assoc($result)) {
echo "列1:" . $row['column1'] . "<br>";
echo "列2:" . $row['column2'] . "<br>";
// 继续输出其他列...
}
mysqli_stmt_close($statement);
mysqli_close($connection);
这样,你就可以遍历mysqli预准备语句并输出结果了。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云