我尝试使用PHP连接到SQL Server以调用其中的过程。但是没有结果返回。请给我一些建议。
示例存储过程:
ALTER PROCEDURE [MemberJoin]
@username varchar(25),
@password varchar(50),
AS
If (EXISTS(SELECT username FROM tbl_user WHERE username = @username ))
Begin
RETURN -2
End
BEGIN TRANSACTION
BEGIN
INSERT INTO tbl_user (username , password ) VALUES (@username, @password)
If (@@ERROR <> 0 OR @@ROWCOUNT = 0)
Begin
ROLLBACK TRANSACTION
RETURN -3
End
COMMIT TRANSACTION
END
RETURN 1
PHP代码
$return = null;
$server = "LOCALHOST\\SQLEXPRESS";
$connectionInfo = array( "Database"=>"SHOP", "UID"=>"sa", "PWD"=>"");
$Conn = sqlsrv_connect( $server, $connectionInfo);
$sql = "{call ? = MemberJoin(@username=?,@password=?)}";
$param = [
[&$return, SQLSRV_PARAM_OUT],
['testingsr', SQLSRV_PARAM_IN],
['12345667', SQLSRV_PARAM_IN],
];
$stmt = sqlsrv_query ( $Conn , $sql, $param );
echo($return);
结果为空,没有错误。 我希望返回值为 1,-2 或 -3
UYOU