【发布时间】:2016-03-18 05:01:50
【问题描述】:
我通过PDO 传递一个大小合适的SQL 服务器TRANSACTION,格式如下:
$sql = "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN TRANSACTION;
DECLARE @id [int];
//Check whether specific record exists with a SELECT
//If it doesn't, create records on two tables
//Check whether record exists again with another sSELECT (it will now) and assign the selected ID to @id
//Update records on the two tables where ID = @id
COMMIT TRANSACTION;";
这很好用,我可以愉快地UPSERT 一整天。但是,我想检索 @id 的值以更新调用对象以供以后使用,理想情况下不需要编写另一个单独的选择查询,并且无法找到可靠的获取方法。
fetch() 在不需要 INSERTs 时将其带回(即记录存在,因此仅调用 UPDATEs),但在调用 INSERTs 时不会。
【问题讨论】:
标签: php sql-server pdo