Это простой, но рабочий пример.
Часть базы данных:
USE [TestDatabase]
CREATE PROCEDURE [TestProcedure]
@P1 int OUTPUT,
@P2 int OUTPUT,
@P3 int OUTPUT,
@P4 int OUTPUT,
@P5 int OUTPUT,
@P6 int OUTPUT,
@P7 int OUTPUT,
@P8 int OUTPUT,
@P9 int OUTPUT,
@P10 int OUTPUT
AS
BEGIN
SET NOCOUNT ON;
-- It's very basic example.
-- Put here your own SQL statements, which must return single values
SELECT @P1 = 1
SELECT @P2 = 2
SELECT @P3 = 3
SELECT @P4 = 4
SELECT @P5 = 5
SELECT @P6 = 6
SELECT @P7 = 7
SELECT @P8 = 8
SELECT @P9 = 9
SELECT @P10 = 10
END
Часть PHP:
<?php
// Connection
$server = 'server\instance,port';
$cinfo = array(
"Database"=>'TestDatabase',
"UID"=>"User",
"PWD"=>"Password"
);
$conn = sqlsrv_connect($server, $cinfo);
if( $conn === false )
{
echo "Error (sqlsrv_connect): ".print_r(sqlsrv_errors(), true);
exit;
}
// Call stored procedure
$sql = '{call TestProcedure(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}';
$p1 = 0;
$p2 = 0;
$p3 = 0;
$p4 = 0;
$p5 = 0;
$p6 = 0;
$p7 = 0;
$p8 = 0;
$p9 = 0;
$p10 = 0;
$params = array(
array(&$p1, SQLSRV_PARAM_INOUT),
array(&$p2, SQLSRV_PARAM_INOUT),
array(&$p3, SQLSRV_PARAM_INOUT),
array(&$p4, SQLSRV_PARAM_INOUT),
array(&$p5, SQLSRV_PARAM_INOUT),
array(&$p6, SQLSRV_PARAM_INOUT),
array(&$p7, SQLSRV_PARAM_INOUT),
array(&$p8, SQLSRV_PARAM_INOUT),
array(&$p9, SQLSRV_PARAM_INOUT),
array(&$p10, SQLSRV_PARAM_INOUT)
);
$stmt = sqlsrv_query($conn, $sql, $params);
if( $stmt === false ) {
echo "Error (sqlsrv_query): ".print_r(sqlsrv_errors(), true);
exit;
}
// Output parameters are available after consuming all resultsets.
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
// Output
echo 'Parameters values'."</br>";
echo 'Parameter 1: '.$p1."</br>";
echo 'Parameter 2: '.$p2."</br>";
echo 'Parameter 3: '.$p3."</br>";
echo 'Parameter 4: '.$p4."</br>";
echo 'Parameter 5: '.$p5."</br>";
echo 'Parameter 6: '.$p6."</br>";
echo 'Parameter 7: '.$p7."</br>";
echo 'Parameter 8: '.$p8."</br>";
echo 'Parameter 9: '.$p9."</br>";
echo 'Parameter 10: '.$p10."</br>";
?>