note 110977 modified in pdo.lastinsertid by danbrown

From: Date: Thu, 17 Jan 2013 15:26:44 +0000
Subject: note 110977 modified in pdo.lastinsertid by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193146@lists.php.net to get a copy of this message
Easiest solution I've found for MSSQL to obtain the last inserted ID is <?php $STH = $DBH->query("SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int)"); $STH->execute(); $result = $STH->fetch(); print $result[0]; ?> --was-- Easiest solution I've found for MSSQL to obtain the last inserted ID is $STH = $DBH->query("SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int)"); $STH->execute(); $result = $STH->fetch(); print $result[0]; from this link http://www.yiiframework.com/forum/index.php/topic/24275-solved-sql-server-2008-returning-blank-lastinsertid/ Looks like it is also possible to update the framework file too so that the function lastInsertId works. http://php.net/manual/en/pdo.lastinsertid.php

« previous php.notes (#193146) next »