$conn = new mysqli(.....);
$param = $_GET['manf'];
$stmt = $conn->prepare('select manf from manf where manf = ?');
$stmt->bind_param('s', $param);
$stmt->execute();
$stmt->store_result();
echo $stmt->num_rows;
$result = $stmt->get_result();
if(!$result){
die(mysql_error());
}
while($row = $result->fetch_assoc()){
echo $row['manf'];
}
echo $stmt->num_rows
打印右键但是我无法从while语句中获得结果。我也试过mysqli::bind_result
,但没有奏效。
我该如何解决这个问题?为获取你需要使用$stmt->fetch()
PHP MySQL:如何从预准备语句中获得结果?
$conn = new mysqli(.....);
$param = $_GET['manf'];
$stmt = $conn->prepare('select manf from manf where manf = ?');
$stmt->bind_param('s', $param);
$stmt->execute();
$stmt->bind_result($result);
echo $stmt->num_rows;
while($stmt->fetch()){
echo $result;
}
$stmt->close();
:
可能不相关,但'die(mysql_error())'在这段代码中不起作用 - 您需要使用'die($ stmt-> error)'来代替。 – andrewsi
可能的重复http://stackoverflow.com/questions/33220057/fatal-error-with-fetch-assoc-inside-a-function – Progman
是的,我在等待多行 – soonoo