PDO lastInsertId()不适用于MS SQL [英] PDO lastInsertId() not working for MS SQL
本文介绍了PDO lastInsertId()不适用于MS SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PDO运行插入查询,然后使用lastInsertId()获取新创建的ID.这一切都在我的本地主机环境上进行.
I am running an insert query using PDO and then getting the newly created Id with lastInsertId(). This is all working on my localhost environment.
当我将完全相同的代码移到服务器上时,即使insert语句起作用并将新行插入到数据库中,lastInsertId()始终返回空白.这是我配置中的设置吗?感谢您的帮助.
When I move the exact same code onto a server, the lastInsertId() is always returning blank, even though the insert statement works and inserts the new row into the database. Would this be a setting in my configuration? Any help is appreciated.
$insertstmt = $dbinsert->prepare($insertsql);
// bindParams ...
$insertstmt->execute();
// always blank
$id = $dbinsert->lastInsertId();
$dbinsert = null;
推荐答案
I ended up replacing lastInsertId() by using this method: http://php.net/manual/en/pdo.lastinsertid.php#105580
$temp = $sth->fetch(PDO::FETCH_ASSOC);
这篇关于PDO lastInsertId()不适用于MS SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文