Problem in executing Stored Procedure on SQL Server Via PHP

61 views Asked by At

I'm running the following code:

$conn = sqlsrv_connect( $serverName, $connectionInfo);

$affiliateId = 0;
$month = 10;
$year = 2023;
$groupid = 17;
$search = '';

$procedure_params = array(
    array(&$affiliateId, SQLSRV_PARAM_IN),
    array(&$month, SQLSRV_PARAM_IN),
    array(&$year, SQLSRV_PARAM_IN),
    array(&$groupid, SQLSRV_PARAM_IN),
    array(&$search, SQLSRV_PARAM_IN)
);

$sql = "EXEC [dbo].[smart_getAffiliateLeadListSearch] @AffiliateId = ?, @month = ?, @year = ?, @groupId = ?, @search = ?";

$stmt = sqlsrv_prepare($conn, $sql, $procedure_params);


if( !$conn ) {
    echo 'Connection error<br>';
    die( '<pre>'.print_r( sqlsrv_errors(), true).'</pre>');
} else if( !$stmt ) {
    echo 'Statment error<br>';
    die( '<pre>'.print_r( sqlsrv_errors(), true).'</pre>');
} else if( sqlsrv_execute( $stmt ) === false ) {
    echo 'Execution error<br>';
    die( '<pre>'.print_r( sqlsrv_errors(), true).'</pre>');
}

I'm getting the following output

Execution error

Array
(
    [0] => Array
        (
            [0] => 01000
            [SQLSTATE] => 01000
            [1] => 0
            [code] => 0
            [2] => [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Oct  1 2023 12:00AM
            [message] => [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Oct  1 2023 12:00AM
        )

    [1] => Array
        (
            [0] => 01000
            [SQLSTATE] => 01000
            [1] => 0
            [code] => 0
            [2] => [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Nov  1 2023 12:00AM
            [message] => [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Nov  1 2023 12:00AM
        )

)

I don't understand the errors. it seems the error messages are just dates.
I'd love some help.

I've tried different Syntax for the query (with and without brackets, with and without the prepending [dbo]). I've tried using the sqlsrv_prepare as well as sqlsrv_query. got almost the same results.

I'm expecting to get data but the sqlsrv_execute keep giving me errors.

0

There are 0 answers