Re: Re: MSSQL equivalent for mysql_insert_id ?
| From: | (Hace) | Date: | Wed, 07 Nov 2001 10:32:24 +0000 |
| Subject: | Re: Re: MSSQL equivalent for mysql_insert_id ? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-14083@lists.php.net to get a copy of this message | ||
On Tue, 6 Nov 2001 16:49:53 +0100 , Richard Hillström (GIS) wrote:
>Can someone show me how it is done?
Thanks to the suggestion from l0t3k, I've now hacked the following
function into my dbRecordset class:
function getlastinsertedId ()
{
// this function should only be called right after
// the usual ExecuteSQL had done the INSERT query
$this->sqlResultLastId = mssql_query("SELECT @@IDENTITY as newid",
$this->sqlConn);
if (mssql_num_rows($this->sqlResultLastId) > 0) {
$dbResult = mssql_fetch_array($this->sqlResultLastId);
echo $dbResult["newid"];
return $dbResult["newid"];
} else { return false; }
// return mysql_insert_id();
}
It's not perfect though: what happens when two users simultaneously
insert a new record?
I have to rewrite to use batch-functionality provided by MSSQL so that
'local lastinserted-id's' are taken...
>its the value returned by the query "SELECT @@IDENTITY"
>
>Hace <why@do-youread.this> wrote in message
>news:3bead00e.10919721@news.php.net...
>>
>>
>> Is there a MSSQL equivalent for:
>>
>>
>> function getlastinsertedId ()
>> {
>> return mysql_insert_id();
>> }
>>
>>
>> I use the above function to retrieve the 'id' of the last inserted
>> record from an insert-query.
>>
>> If there is another way to accomplish the same thing with MS-SQL
>> server and PHP, please let me know.
>>
>> Thanks in advance,
--
http://hace.dyndns.org/
Everything I say is my own opinion and not necessarily that of my employer.