我知道执行语句的输出是bool。但是,如何得到如下所示的SELECT语句的结果?
<?php
/* Execute a prepared statement by passing an array of insert values */
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour');
$sth->execute(array(':calories' => $calories, ':colour' => $colour));
?>
$ sth将为TRUE或FALSE。我感兴趣的是包含名称,颜色等的返回行。
谢谢!
答案 0 :(得分:0)
$result = $sth->get_result();
while ( $row = $result->fetch_assoc() ) {
echo $row['name'];
}