gpt4 book ai didi

php - 使用准备好的语句获取多行

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:03:13 30 4
gpt4 key购买 nike

<分区>

我对准备好的陈述很陌生,不确定我这样做是否正确。

这是我的尝试:

$currgame = 310791;

$sql = "SELECT fk_player_id, player_tiles, player_draws, player_turn, player_passes, swapped FROM ".$prefix."_gameplayer WHERE fk_game_id = ?";
$stmt = $mysqli->stmt_init();

$data = array();
if($stmt->prepare($sql)){
$stmt->bind_param('i', $currgame);
$stmt->execute();

$fk_player_id = null; $player_tiles = null; $player_draws = null; $player_turn = null; $player_passes = null; $swapped = null;
$stmt->bind_result($fk_player_id, $player_tiles, $player_draws, $player_turn, $player_passes, $swapped);

$res = $stmt->get_result();

while ($row = $res->fetch_assoc()){
$data[] = $row;
}
$stmt->close();
}

// to display own games
foreach ($data as $row) {
if ($row['fk_player_id'] == $playerid) {

$udraws = $row['player_draws']+1;
$upass = $row['player_passes'];
$uswaps = $row['swapped'];

echo 'uDraws: '.$udraws.'<br>';
echo 'uPass: '.$upass.'<br>';
echo 'uSwaps: '.$uswaps.'<br><br>';
}
}
// to display other games
foreach ($data as $row) {
if ($row['fk_player_id'] != $playerid) {

$opponent = $row['fk_player_id'];
$oppTiles = $row['player_tiles'];

$odraws = $row['player_draws']+1;
$opass = $row['player_passes'];
$oswaps = $row['swapped'];

echo 'oID: '.$opponent.'<br>';
echo 'oTiles: '.$oppTiles.'<br>';

echo 'oDraws: '.$odraws.'<br>';
echo 'oPass: '.$opass.'<br>';
echo 'oSwaps: '.$oswaps.'<br><br>';

}
}

尝试运行此程序时出现“ServerError”:是 $res = $stmt->get_result(); 导致错误,但不确定原因。

PHP Fatal error: Call to undefined method mysqli_stmt::get_result() in /home/mypage/public_html/TEST/preparedstatement.php on line 61

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com