Kyl*_*son 7 php pdo lastinsertid
我已经尝试了很多方法来获取最后一个插入ID以及下面的代码(较大类的snipplet),现在我放弃了.
有谁知道如何让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;
Run Code Online (Sandbox Code Playgroud)
Ant*_*ney 12
在您的代码段中,我看到了一些可能对问题产生影响的轻微不一致.例如,在准备您使用的SQL语句的代码中,
$stmt = $this->dbh->prepare($sql);
Run Code Online (Sandbox Code Playgroud)
注意$this关键字.然后要检索ID,你打电话,
$dbh->lastInsertId();
Run Code Online (Sandbox Code Playgroud)
你试过用过吗?
$this->dbh->lastInsertId();
| 归档时间: |
|
| 查看次数: |
10339 次 |
| 最近记录: |