2
我在使用預準備語句方面很新,並且想知道是否應該在每次調用後關閉stmt_init(),還是可以保持打開狀態?在使用預準備語句開始新語句之前關閉語句對象
$stmt = $mysqli->stmt_init();
if($stmt->prepare("SELECT player_draws, player_turn, player_passes, swapped FROM ".$prefix."_gameplayer WHERE fk_game_id = ? AND fk_player_id = ?")){
$stmt->bind_param('ii', $currgame, $playerid);
$stmt->execute();
$stmt->bind_result($udraws, $uturn, $upass, $uswaps);
$stmt->fetch();
echo $udraws.'-'.$uturn.'-'.$upass.'-'.$uswaps.'<br>';
// Close statement object
$stmt->close();
}
$stmt = $mysqli->stmt_init();
if($stmt->prepare("SELECT player_draws, player_turn, player_passes, swapped FROM ".$prefix."_gameplayer WHERE fk_game_id = ? AND fk_player_id != ?")){
$stmt->bind_param('ii', $currgame, $playerid);
$stmt->execute();
$stmt->bind_result($odraws, $oturn, $opass, $oswaps);
$stmt->fetch();
echo $odraws.'-'.$oturn.'-'.$opass.'-'.$oswaps.'<br>';
// Close statement object
$stmt->close();
}
對於考慮調用的數據庫,其中一個更好嗎?
在此先感謝!
但在第一個我想從WHERE獲取數據fk_player_id =?在第二個我想要的地方fk_player_id!=?。我怎麼能把它放在同一個? – Mansa
對不起,現在看到了,認爲他們是一樣的。你應該可以使用相同的$ mysqli-> stmt_init();對於兩者,但您需要重新準備第二個查詢。 – Manatok
感謝:-)你一直在幫助很大! – Mansa