sql - php to return id using Scope_identity -


searching other articles have come conclusion need use scope_identity() return value of primary key gets generated when insert row ms sql table. not clear me php need return value. being new, have gotten away until borrowing code predecessor run sql queries, have been situations returning results array using while loop. please advise correct code.

$query = "insert mytable (title,author)           values('".sql_safe($title)."', '"sql_safe($author)."'); select scope_identity() myid;";  $result = odbc_exec($con1, $query); 

until have ever needed use

while($row = odbc_fetch_array($result)){ } 

but correct way of referring myid ?

i struggled while , in end solution involved going mssql_query driver

$query ="        insert powerview.dl_documentlist (title,liveversion,author,location,locked,lockedbyid)                 values('".sql_safe($title)."',1.0,'".sql_safe($author)."','".sql_safe($location)."','1',".$lockedbyid.");                  select scope_identity() id;                 return;              ";      $result = mssql_query($query);           $result = mssql_fetch_object($result);      $docid = $result->id;   

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -