我正在尝试使用以下给出的答案:如何获取 MySQL 中最后更新行的 ID?
我想要更新的行的 ID。但是下面的错误是不起作用的
Fatal error: Call to a member function fetch_assoc() on a non-object
。
$query = "
SET @update_id := 0;
UPDATE locations SET owner_player_id='$player_id', id=(SELECT @update_id := id)
WHERE game_id='$game_id' LIMIT 1;
SELECT @update_id;
";
$result = $mysqli->query($query);
$row = $result->fetch_assoc();
$location_id = $row['update_id'];
谢谢
编辑:
$mysqli->错误给出You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE locations SET owner_player_id='5', id=(SELECT @update_id := id) WHERE gam' at line 1