<?php
$conn = mysqli_connect("localhost","root","root","world");
$stmt = $conn->prepare("SELECT * FROM alfas ORDER BY year");
$stmt->execute();
$stmt->bind_result($year, $model, $accel);
print "<table border='1'>\n";
print "<tr><th>Model</th><th>0-100 km/h</th></tr>\n";
while($stmt->fetch()){
    print "<tr><td>$year $model</td><td>{$accel} sec</td></tr>\n";
}
print "</table>\n";
?>

PHP预备语句 绑定变量输出变量获取数据的示例代码

执行效果:

PHP预备语句 绑定变量输出变量获取数据的示例代码

bind_result是在执行execute()之后运行,会将获取到的行数据按列分配到指定的3个变量之中.和上例输入变量的bind_param恰好相反,bind_param是介于prepare和execute之间运行的.

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2022-02-04
  • 2021-05-27
  • 2021-10-20
猜你喜欢
  • 2022-01-27
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
  • 2021-05-16
  • 2021-05-18
  • 2021-05-18
相关资源
相似解决方案