mysql insert语句后如何获取insert数据的主键值自动编号

方法很简单的,mysql数据自带的了mysql_insert_id ( );函数

使用方法:

insert into(a')values('b')

$nid =last_insert_id();

方法二:

LAST_INSERT_ID(),不过关于这个函数,与mysql_insert_id()比较有很多的区别,mysql_insert_id ()是直接获取当前session的insert_id,而LAST_INSERT_ID()是SQL函数,
需要通过执行SQL来获得,如:SELECT LAST_INSERT_ID();显然这两个效果是一样的,
但执行一次SQL要耗费很多资源,不如直接通过mysql_insert_id()获得内存中的值快得多

相关文章:

  • 2021-12-17
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2021-06-22
  • 2021-07-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
相关资源
相似解决方案