php – mysqli最后插入的id

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – mysqli最后插入的id脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我想将图像与Firstname,lastname相关联…如何检索最后一行并使用它来插入到其他表?我试过$image = $ mysqli-> insert_id;然后绑定,但它不工作.有人可以帮我吗?
$image = $MysqLi->insert_id;//this should come From table2
 $stmt = $MysqLi->PRepare("
  insert into table1 (username,firstname,lastname,image) 
  select ?,?,image from table2 t2 where username = ? and  t2.id = ? 
   ");
 $stmt->bind_param('sssss',$username,$fname,$lname,$image);
 $stmt->execute();
MysqLi :: $insert_id – MysqLi_insert_id – 返回上次查询中使用的自动生成的ID,示例:
$MysqLi = new MysqLi("localhost","my_user","my_password","world");

/* check connection */
if (MysqLi_connect_errno()) {
    printf("Connect Failed: %s\n",MysqLi_connect_error());
    exIT();
}

$MysqLi->query("CREATE TABLE myCity LIKE City");

$query = "INSERT INTO myCity VALUES (NULL,'Stuttgart','DEU',617000)";
$MysqLi->query($query);

printf ("New Record has id %d.\n",$MysqLi->insert_id);

/* drop table */
$MysqLi->query("DROP TABLE myCity");

/* close connection */
$MysqLi->close();

产量

参考

> PHP mysqli_insert_id: http://www.php.net/manual/en/mysqli.insert-id.php

脚本宝典总结

以上是脚本宝典为你收集整理的php – mysqli最后插入的id全部内容,希望文章能够帮你解决php – mysqli最后插入的id所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。