Hola estoy tratando de obtener un valor de un procedimiento almacenado con php pero no logro obtener el resultado del PA.
PROCEDURE:
ALTER PROCEDURE [dbo].[JSP_GetNextAutonumber](@Type VARCHAR(20))
AS
WHILE 1 = 1 BEGIN
DECLARE @Nbr VARCHAR(50);
UPDATE Auto_number SET @Nbr = Last_Nbr += 1 WHERE Type = @Type
IF @Type = 'SalesOrder'BEGIN
IF NOT EXISTS(SELECT 1 FROM SO_Header WHERE Sales_Order = @Nbr) BEGIN
SELECT @Nbr
return @Nbr;
END
END ELSE IF @Type = 'PurchaseOrder' BEGIN
IF NOT EXISTS(SELECT 1 FROM PO_Header WHERE PO = @Nbr) BEGIN
SELECT @Nbr
return @Nbr;
END
END ELSE IF @Type = 'Packlist' BEGIN
IF NOT EXISTS(SELECT 1 FROM Packlist_Header WHERE Packlist = @Nbr) BEGIN
SELECT @Nbr
return @Nbr;
END
END ELSE IF @Type = 'Invoice' BEGIN
IF NOT EXISTS(SELECT 1 FROM Invoice_Header WHERE Document = @Nbr) BEGIN
SELECT @Nbr
return @Nbr;
END
END
END
PHP
$serverName = "LAPTOP-5HT35E0A\SQLEXPRESS";
$uid = "sa";
$pwd = "123";
$databaseName = "Alkon_Prod";
$connectionInfo = array( "UID"=>$uid,
"PWD"=>$pwd,
"Database"=>$databaseName);
/* Connect using SQL Server Authentication. */
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$procedure_params = array("Packlist");
$tsql = "EXEC JSP_GetNextAutonumber @Type = ?;";
/* Execute the query. */
$stmt = sqlsrv_prepare($conn, $tsql, $procedure_params);
if( !$stmt ) {
echo (sqlsrv_errors());
}
$result = sqlsrv_execute($stmt);
if ( !$result ) {
echo Exception(sqlsrv_errors(), 0);
}
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC) ;
echo "Col1: ".$row[0]."\n";
echo "-----------------<br>\n";
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
Y en Sql MS si sale el resultado