note 105582 added to function.mssql-query
| From: | vavra at 602 dot cz | Date: | Tue, 30 Aug 2011 12:35:26 +0000 |
| Subject: | note 105582 added to function.mssql-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182820@lists.php.net to get a copy of this message | ||
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;
}
}
<?>
----
Server IP: 69.147.83.197
Probable Submitter: 94.112.242.230
----
Manual Page -- http://www.php.net/manual/en/function.mssql-query.php
Edit -- https://master.php.net/note/edit/105582
Del: integrated -- https://master.php.net/note/delete/105582/integrated
Del: useless -- https://master.php.net/note/delete/105582/useless
Del: bad code -- https://master.php.net/note/delete/105582/bad+code
Del: spam -- https://master.php.net/note/delete/105582/spam
Del: non-english -- https://master.php.net/note/delete/105582/non-english
Del: in docs -- https://master.php.net/note/delete/105582/in+docs
Del: other reasons-- https://master.php.net/note/delete/105582
Reject -- https://master.php.net/note/reject/105582
Search -- https://master.php.net/manage/user-notes.php