6
I created a register with some 58 data.
As I was creating, I was testing and the data was entering the BD, and every time an insertion was made, I took the id
of the last data set/group inserted.
Only if I "give one refresh on the page" when I will make a new registration, the data are no longer registered in the BD, it is as if the id
of the last record was lost because I put a echo
to show the id
created and now see no more.
The mistake that happens is:
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -14 [code] => -14 [2] => An invalid Parameter was passed to sqlsrv_next_result. [message] => An invalid Parameter was passed to sqlsrv_next_result. ) 1
Can anyone tell me what might be going on?
$sqlProto = "INSERT INTO [RDO].[dbo].[Protocolo] (titulo, $transicaoCentralCorresp) VALUES (?,?)";
$sqlProto = "INSERT INTO [RDO].[dbo].[Protocolo] (titulo, $transicaoCentralCorresp) VALUES (?,?); SELECT SCOPE_IDENTITY() AS last_id ";
$paramsProto = array($titulo, $transicaoCentralCorresp);
$stmt = sqlsrv_query( $conn, $sqlProto, $paramsProto);
if($next_result){
$item = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
$uId = $item['last_id'];
echo "Último id inserido ". $uId."<br>";
}else{
die(print_r(sqlsrv_errors()));
}
Tip: Is there by any chance Rigger in this process? This can influence the return, and confirm that for the return is used the command
@id_Transacao = SCOPE_IDENTITY()
, who takes the lastinsert
of the main selection, not of another section.– neibala
But you do the
SELECT
before to get the last ID inserted ? I only seeINSERT
in your code. But you can follow the suggestion of the Kaduamaral.– Diego Souza