$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