您确定您执行的最后一个查询是INSERT吗?
mysqli->insert_id
似乎是正确的答案:
Return Values
The value of the
AUTO_INCREMENT
field that was updated
by the prevIoUs query. Returns zero if
there was no prevIoUs query on the
connection or if the query did not
update anAUTO_INCREMENT
value.