【发布时间】:2011-02-10 04:06:54
【问题描述】:
我已经尝试了很多方法来使用下面的代码(来自大类的片段)获取最后插入的 ID,现在我已经放弃了。
有人知道如何让 PDO lastInsertId 工作吗?
提前致谢。
$sql = "INSERT INTO auth (surname, forename, email, mobile, mobilepin, actlink, regdate) VALUES (:surname, :forename, :email, :mobile, :mobpin, :actlink, NOW())";
$stmt = $this->dbh->prepare($sql);
if(!$stmt) {
return "st";
}
$stmt->bindParam(':surname', $this->surname);
$stmt->bindParam(':forename', $this->forename);
$stmt->bindParam(':email', $this->email);
$stmt->bindParam(':mobile', $this->mobile);
$stmt->bindParam(':mobpin', $this->mobilePin);
$stmt->bindParam(':actlink', $this->actlink);
$result = $stmt->execute();
//return var_dump($result);
$arr = array();
$arr = $stmt->errorInfo();
$_SESSION['record'] = 'OK' . $dbh->lastInsertId();
$arr .= $_SESSION['record'];
return $arr;
【问题讨论】:
-
你能不能提一下它是怎么不工作的?只是说,它不起作用会导致其他人假设问题可能是什么。信息越多,答案就越多。
标签: php pdo lastinsertid