[英]PHP MySQL: How to get result from prepared statement?
$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
但沒有用。
我怎樣才能解決這個問題?
嘗試這個:
$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();
$stmt->bind_result($result);
echo $stmt->num_rows;
while($stmt->fetch()){
echo $result;
}
$stmt->free_result();
$stmt->close();
要獲取,您需要使用$stmt->fetch()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.