note 105582 deleted from function.mssql-query by cmb
| From: | cmb@php.net | Date: | Sun, 23 Jun 2019 14:26:17 +0000 |
| Subject: | note 105582 deleted from function.mssql-query by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211381@lists.php.net to get a copy of this message | ||
Note Submitter: vavra at 602 dot cz
----
The scenario with adding SELECT SCOPE_IDENTITY after INSERT works. But in my a little bit
complicated schema I got false when I called sqlsrv_fetch(.)
I modified reading SCOPE_IDENTITY as: "Read the last integer value obtained".
I suppose this is because I have several triggers that makes also insert after main insert call and
sql server returns number of affected rows in Sql Management Studio). In php it returns only false
when fetch called. So I must jump over all this 'false' rows.
<?php
$resource = sqlsrv_query($con, 'INSERT....; SELECT SCOPE_IDENTITY()');
$scope_identity =null;
while ( sqlsrv_next_result($resource) )
{
$fr = sqlsrv_fetch($resource);
if ($fr===false)
{
continue;
}
$colval = sqlsrv_get_field($resource, 0, SQLSRV_PHPTYPE_INT);
if (is_int($colval))
{
$scope_identity=$colval;
}
}
?>