我正在学习PHP,我正在尝试使用MySQLi准备好的语句。我知道我的SQL正好返回我想要的东西,它在PHPmyAdmin中返回就好了,只是不在PHP中。
$stmt=mysqli_stmt_init($mysql);
$query = "SELECT name,version,category FROM `software` WHERE id =?";
$stmt = mysqli_stmt_prepare($mysql, $query);
mysqli_stmt_bind_param($stmt, 'i', $sid);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $name, $version, $category);
mysqli_stmt_fetch($stmt);
if (empty($name)){die("No results found.");};
echo "<center><h1><b>" . $name . "</b></h1><br />";
我知道$ sid = 1,因为我可以回应它并设置,我也可以删除绑定参数并设置? 1和相同的结果。
非常感谢任何帮助,谢谢!
答案 0 :(得分:0)
$stmt=mysqli_stmt_init($mysql);
$query = "SELECT name,version,category FROM `software` WHERE id =?";
$stmt = mysqli_stmt_prepare($mysql, $query);
mysqli_stmt_bind_param($stmt, 'i', $sid);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $name, $version, $category);
///try the while
while (mysqli_stmt_fetch($stmt)) {
printf ("%s (%s)\n", $name, $version, $category);
}