Quantcast
Channel: Microsoft Drivers for PHP for SQL Server forum
Viewing all articles
Browse latest Browse all 391

How to execute a stored procedure when using 1 param_in. The SP should return 3 values

$
0
0

Hi,

I have a stored procedure that requires @Date DATETIME

and will return a name (string) with a payout (decimal) and turnover (decimal).

There will be multiple names with decimal values returned.

I can connect to my DB fine but I am having difficulty on the connecting with the stored procedure. 

like so:

/* Connextion to SQL Server */
$server = 'tcp:address';

$credentials = array
(
  'UID'       => 'value',
  'PWD'       => 'value',
  'Database'  => 'value',
  'ReturnDatesAsStrings' =>1

);

$connection = sqlsrv_connect( $server, $credentials );
if( $connection === false )
{
        echo ("failed to connect");
        die( '<pre class="error">' . print_r( sqlsrv_errors(), true ) . '</pre>' );
}

But the parameter part I'm not sure about:

// Define parameter array
$tsql_callSP = " { call SPGetDetails( ?, ?, ?, ? ) } ";
$date = date('d-m-Y');

$params = array(
                  array( $date, SQLSRV_PARAM_IN ),
                  array( $track, SQLSRV_PARAM_OUT ) ,
                  array( $payout, SQLSRV_PARAM_OUT) ,
                  array( $turnover, SQLSRV_PARAM_OUT) ) ;

/* Get sql data */

$stmt = sqlsrv_query( $connection, $tsql_callSP, $params );
if( $stmt === false )
{
        echo ("failed to call  stored proc " );
        die( '<pre class="error">' . print_r( sqlsrv_errors(), true ) . '</pre>' );
}

// Display tracks
$nextTrack = sqlsrv_next_result ( $spConnection ) ;
$row = sqlsrv_fetch_array ( $spConnection );

sqlsrv_free_stmt( $connectoin );
sqlsrv_close ( $connection );

I just keep getting this error:

 [0] => IMSSP
            [SQLSTATE] => IMSSP
            [1] => -61
            [code] => -61

can someone please show me an example of how to return 3 parameters from a stored procedure by providing a date parameter?




CuriousCoder


Viewing all articles
Browse latest Browse all 391

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>