php - 从 Access 获取最后插入 ID

标签 php sql ms-access insert pdo

熟悉MySQL函数LAST_INSERT_ID;是否有类似的功能可以通过 ODBC 对 MS Access 数据库执行相同的查询?

在我的具体案例中,我使用 PHP+PDO 将行插入到 Access 数据库中,并且想知道每次插入执行时的最后一个主键值。

如果此功能不可用,是否有替代方案? (不改变数据库)

谢谢。

最佳答案

似乎Access 2000 或更高版本支持@@IDENTITY 属性。因此,您只需要在 INSERT 之后选择它的值:

select @@IDENTITY from myTable

请参阅 MSDN 链接:Retrieving Identity or Autonumber Values

简而言之:

[...] Microsoft Access 2000 or later does support the @@IDENTITY property to retrieve the value of an Autonumber field after an INSERT. Using the RowUpdated event, you can determine if an INSERT has occurred, retrieve the latest @@IDENTITY value, and place that in the identity column of the local table in the DataSet.

关于php - 从 Access 获取最后插入 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4135437/

相关文章:

php - mkdir() : Permission problems

sql - 多个 id 的更新语句

c# - 如何检查 Access 数据库表中是否存在特定列

sql选择到

c# - 在 C# 中使用 OLEDB 数据提供程序读取 excel 文件时的 FROM 子句

mysql - Microsoft Access 2010 中 OrderByOn 属性中的错误

c# - 使用参数将数据插入access数据库

php - 使用更新查询复制列数据

php - 为什么魔术方法 '__get' 被调用了两次?

php - 如何防止 Laravel 在测试中触发事件?