Mysqli insert id: $mysqli->insert_id; or $ID_user=$stmt->insert_id?

旧巷老猫 提交于 2020-01-05 05:52:26

问题


which one is the correct code in a prepared statement? $ID_user=$mysqli->insert_id; or $ID_user=$stmt->insert_id; ?

$stmt = $mysqli->prepare("INSERT INTO users (first_name, last_name) VALUES (?   ,?)");
$stmt->bind_param("ss",$first_name,$last_name);     
if($stmt->execute())
{
     $ID_user=$mysqli->insert_id;  // or $ID_user=$stmt->insert_id;
}

回答1:


There is absolutely no difference, you can use whatever you wish.



来源:https://stackoverflow.com/questions/43184732/mysqli-insert-id-mysqli-insert-id-or-id-user-stmt-insert-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!