簡體   English   中英

PHP MySQL:如何從准備好的語句中獲取結果?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM