<?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";
?>
执行效果:
bind_result是在执行execute()之后运行,会将获取到的行数据按列分配到指定的3个变量之中.和上例输入变量的bind_param恰好相反,bind_param是介于prepare和execute之间运行的.