您好我在sql server中使用存储过程来插入记录。 PhP中的存储过程是:
$sp_name = "{CALL sp_PersonInfo_Save(@PersonID=?,@FirstName=?,@LastName=?,@SSN=?,@Email=?,@BirthDate=?,@HireDate=?,@TerminationDate=?,@RetirementDate=?,@DeathDate=?,@Gender=?,@MutialStatus=?,@isActive=?,@Status=?,@Address1=?,@Address2=?,@Phone1=?,@Phone2=?,@City=?,@State=?,@Zip=?,@Country=?,@WhoUpdated=?)} ";
$params = array(
array($var_PersonID, SQLSRV_PARAM_IN),
array($var_FirstName, SQLSRV_PARAM_IN),
array($var_LastName, SQLSRV_PARAM_IN),
array($var_SSN2, SQLSRV_PARAM_IN),
array($var_Email, SQLSRV_PARAM_IN),
array($var_BirthDate, SQLSRV_PARAM_IN),
array($var_HireDate, SQLSRV_PARAM_IN),
array($var_TerminationDate, SQLSRV_PARAM_IN),
array($var_RetirementDate, SQLSRV_PARAM_IN),
array($var_DeathDate, SQLSRV_PARAM_IN),
array($var_Gender, SQLSRV_PARAM_IN),
array($var_MaritalStatus, SQLSRV_PARAM_IN),
array($var_IsActive, SQLSRV_PARAM_IN),
array($var_PersonalStatus, SQLSRV_PARAM_IN),
array($var_AddressLine1, SQLSRV_PARAM_IN),
array($var_AddressLine2, SQLSRV_PARAM_IN),
array($var_Phone1, SQLSRV_PARAM_IN),
array($var_Phone2, SQLSRV_PARAM_IN),
array($var_City, SQLSRV_PARAM_IN),
array($var_State, SQLSRV_PARAM_IN),
array($var_ZipCode, SQLSRV_PARAM_IN),
array($var_Country, SQLSRV_PARAM_IN),
array($var_WhoUpdated, SQLSRV_PARAM_IN)
);
$result = sqlsrv_query($gaSql['link'], $sp_name, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET));
我需要获取此插入ID。我尝试使用此代码:
sqlsrv_next_result($result);
sqlsrv_fetch($result);
$lastId = sqlsrv_get_field($result, 0);
但它不起作用....提前致谢