Sorry for my poor english. Here's the problem: i'm trying to reciebe an ID in PHP from a table in sql server express 2014 via sqlsrv driver, an SP and a output parameter.
When i execute de SP and print the output parameter via SSMS everything works just fine. However, when i call the SP from PHP the SP is executed but the output parameter doesn't change.
This is the SP:
ALTER PROCEDURE [dbo].[SiguientePaciente](
@IdExamen int OUTPUT
) AS
BEGIN
SET NOCOUNT ON
SET @IdExamen = (SELECT TOP 1 T.IdExamen FROM TURNOS T WHERE T.Estado = 0 ORDER BY T.FechaHora ASC)
UPDATE TURNOS SET Estado = 1 WHERE IdExamen = @IdExamen
RETURN
END
This is the PHP, assume that $conexion
works:
$idExamen = 0;
$sql = "{CALL SiguientePaciente (?)}";
$params = [&$idExamen, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT, SQLSRV_SQLTYPE_INT];
$stmt = sqlsrv_query($conexion, $sql, $params);
if($stmt !== false){
//sqlsrv_next_result($stmt);
echo $idExamen;
}
else
echo print_r(sqlsrv_errors(), true);
In the end, echo $idExamen
prints 0
EDIT: found an alternative way to do what i want, with a SELECT inside the SP. Then i just fetch de result in PHP
ALTER PROCEDURE [dbo].[SiguientePaciente](
@IdExamen int OUTPUT
) AS
BEGIN
SET NOCOUNT ON
SET @IdExamen = (SELECT TOP 1 T.IdExamen FROM TURNOS T WHERE T.Estado = 0 ORDER BY T.FechaHora ASC)
UPDATE TURNOS SET Estado = 1 WHERE IdExamen = @IdExamen
SELECT @IdExamen AS IdExamen
RETURN;
END