PHP MySQL PDO lastInsertID导致致命错误 [英] PHP MySQL PDO lastInsertID causes fatal error

查看:226
本文介绍了PHP MySQL PDO lastInsertID导致致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试浏览其他帖子,但没有找到我想要的东西.

I tried looking through some other posts, but didn't see anything exactly what I'm looking for.

我有一个数据库查询

$sql = "INSERT INTO groups(Name) VALUES (:name)";
$dbs = $dbo->prepare($sql);

$dbs->bindParam(":name", $_POST['name'], PDO::PARAM_STR);

$dbs->execute();

$groupID = $dbs->lastInsertId();

返回此致命错误:

[Tue Dec 20 13:59:23 2011] [error] [client 127.0.0.1] PHP Fatal error:  Call to undefined method PDOStatement::lastInsertId() in /media/Storage/www/2011/admin/public/ajax.users.php on line 87, referer: http://localhost/2011/admin/public/menu.php?page=users

根据PDO :: lastInsertId()的php手册:

According to the php manual for PDO::lastInsertId():

如果PDO驱动程序不支持此功能,则PDO :: lastInsertId()会触发IM001 SQLSTATE.

If the PDO driver does not support this capability, PDO::lastInsertId() triggers an IM001 SQLSTATE.

如何确定我的服务器是否支持lastInsertId()?在任何地方的错误日志中都看不到IM001.

How would I determine if my server supports lastInsertId()? I do not see IM001 in my error log anywhere.

运行此命令时,数据可以很好地插入,但是我无法在下一组设置组权限的INSERT中使用其ID.

When I run this, the data is inserted fine, but I cannot get its ID to use in the next set of INSERT's that set the group permissions.

推荐答案

lastInsertId()是PDO类的方法,而不是PDOStatement类.

lastInsertId() is a method of the PDO class, not the PDOStatement class.

这应该有效:

$groupID = $dbo->lastInsertId();

这篇关于PHP MySQL PDO lastInsertID导致致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆