How to execute a stored procedure in php using sqlsrv and “?” style parameters

前端 未结 3 835
天涯浪人
天涯浪人 2020-11-29 11:34

I\'ve looked over several other questions that seem (from the titles) the same as this. However, my case is a bit different.

The following works (i.e. I get \"succes

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 12:07

    Make sure you set this or you will always get errors returned if the stored procedure has messages being returned.

    sqlsrv_configure('WarningsReturnAsErrors',0);
    
    //Full working code below
    
    $sql = "{call NameOfDatabase.NameOfOwner.StoredProcedureName(?,?)}";
    
    $params = array($param1, $param2); 
    
    if ($stmt = sqlsrv_prepare($conn, $sql, $params)) {
        echo "Statement prepared.

    \n"; } else { echo "Statement could not be prepared.\n"; die(print_r(sqlsrv_errors(), true)); } if( sqlsrv_execute( $stmt ) === false ) { die( print_r( sqlsrv_errors(), true)); }else{ print_r(sqlsrv_fetch_array($stmt)); }

提交回复
热议问题