如何从 PDO 获取最后插入的插入行 ID
问题描述
我在 PHP 中遵循 mvc 结构,我想检索最后插入的行 ID.
I am following mvc structure in PHP and I want to retrieve last inserted row ID.
我创建了以下 sql 代码:
但不幸的是我收到了这个错误:致命错误:调用未定义的方法 PDOStatement::lastInsertId()
but unfortunately I ma getting this error: Fatal error: Call to undefined method PDOStatement::lastInsertId()
我也试过这个 stack 链接,但对我不起作用,所以如果你帮我检索 ID,我会很高兴.
I have also tried this stack links but not worked for me so I will happy if you help me for retrieve ID.
我也在这里分享我的 controller.php 文件.
I am also sharing my controller.php file here.
推荐答案
大功告成.
如果您查看 lastInsertId 的手册页,则会在数据库句柄 - 您当前正在语句中调用它.
If you look at the manual page for lastInsertId, it's called on the database handle - you're currently calling it on the statement.
你只需要打电话:
这篇关于如何从 PDO 获取最后插入的插入行 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!