为什么 PDO 的 Oracle 驱动程序不实现 lastInsertId()?
我在 PDO 中收到此错误:
错误:消息:PDO::lastInsertId() [pdo.lastinsertid]: SQLSTATE[IM001]:驱动程序不支持此功能:驱动程序支持 不支持lastInsertId()
当尝试从 Oracle 数据库获取最后插入的 ID 时, 。我将序列字符串添加到最后一个插入 id 函数,但仍然不起作用。对于 Oracle 上的 PDO 错误,Google 没有透露太多信息。
I get this error in PDO:
error: Message: PDO::lastInsertId() [pdo.lastinsertid]:
SQLSTATE[IM001]: Driver does not support this function: driver does
not support lastInsertId()
when trying to get last inserted id from an oracle database. I added the sequence string to the last insert id function but still not working. Google doesn't say much regarding this error on Oracle with PDO.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Oracle 没有自动增量列,因此不像 MySQL 那样支持 lastInsertId。您必须使用 Oracle 序列“手动”实现等效的操作。
为每个需要它的表创建一个 oracle 序列,并在需要执行插入时使用 NEXTVAL 检索它,然后在表中插入时使用该值。
Oracle doesn't have autoincrement columns, so lastInsertId isn't supported in the same way as for MySQL. You have to implement the equivalent "by hand" using Oracle sequences.
Create an oracle sequence for every table that requires it, and use NEXTVAL to retrieve it whenever you need to do an insert, then use that value when inserting in the table.
在 Oracle 中,您应该为需要自动增量列的表创建一个 Oracle 序列。
如果你想插入,那么你可以同时完成,而不是查询
nextIncrementId
并插入,如下所示:如果你只想知道最后一个插入 id,那么不要使用nextval 因为每当您调用它时,它都会将值增加到下一个值。为此,您应该使用 CURRVAL。下面是一个示例:
调试:
print_r($lastInserId);
In Oracle, you should have created an oracle sequence for tables which requires an auto increment column.
If you want to insert, then you can do it in the same time rather than query
nextIncrementId
and insert as below:If you just want to know the last insert id, then don't use nextval because whenever you call it, it increment the value to the next one. You should use CURRVAL for that purpose. Below is an example:
Debug:
print_r($lastInserId);