dongsha2792
2015-11-13 19:19
浏览 99
已采纳

在PHP中使用sqlsrv执行存储过程

I'm executing a stored procedure using sqlsrv in a php code like this:

    $tsql_callSP = "{call cnt.stproc1(?)}";
    $rotCode = '1111';
    $params = array( 
                     array($rotCode, SQLSRV_PARAM_IN),
                   );

    $serverName = "xxxxxxx\wwwwwww"; //serverName\instanceName
    $connectionInfo = array( "Database"=>"aaaaaaaaaaa", "UID"=>"bbbbbbb", "PWD"=>"ccccccc");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);

    /* Execute the query. */
    $stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params);
    if( $stmt3 === false )
    {
         echo "Error in executing statement 3.
";
         die( print_r( sqlsrv_errors(), true));
    }

The Stored Procedure is executed in the DB successfully and does what it has to do, but in my php code i always fall in the failiure if (stmt3 === false) receiving the following error:

     Array ( [0] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]0510620150922777 [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]0510620150922777 ) [1] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]UPDATE 004 [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]UPDATE 004 ) )

What is wrong here? why does it get executed well, but the driver handles me this error?

图片转代码服务由CSDN问答提供 功能建议

我正在使用sqlsrv在php代码中执行存储过程,如下所示:

  $ tsql_callSP =“{call cnt.stproc1(?)}”; 
 $ rotCode ='1111'; 
 $ params = array(
 array($ rotCode,SQLSRV_PARAM_IN),
)  ; 
 
 $ serverName =“xxxxxxx \ wwwwwww”;  // serverName \ instanceName 
 $ connectionInfo = array(“Database”=>“aaaaaaaaaaa”,“UID”=>“bbbbbbb”,“PWD”=>“ccccccc”); 
 $ conn = sqlsrv_connect(  $ serverName,$ connectionInfo); 
 
 / *执行查询。  * / 
 $ stmt3 = sqlsrv_query($ conn,$ tsql_callSP,$ params); 
 if($ stmt3 === false)
 {
 echo“执行语句3时出错。
”; 
 die  (print_r(sqlsrv_errors(),true)); 
} 
   
 
 

存储过程在DB中成功执行并完成它必须执行的操作,但是 我的php代码我总是属于failiure if(stmt3 === false)收到以下错误:

  Array([0] => Array([0] =  > 01000 [SQLSTATE] => 01000 [1] => 0 [code] => 0 [2] => [Microsoft] [用于SQL Server的ODBC驱动程序11] [SQL Server] 0510620150922777 [message] =  > [Microsoft] [用于SQL Server的ODBC驱动程序11] [SQL Server] 0510620150922777)[1] =>数组([0] => 01000 [SQLSTATE] => 01000 [1] => 0 [代码 ] => 0 [2] => [Microsoft] [用于SQL Server的ODBC驱动程序11] [SQL Server]更新004 [消息] => [Microsoft] [用于SQL Server的ODBC驱动程序11] [SQL Server]更新 004))
   
 
 

这里有什么问题? 为什么它执行得很好,但驱动程序处理我这个错误?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyishen5796 2015-11-13 19:28
    已采纳

    Done. It was not an error, just a warning. However, sqlsrv treats warnings as errors unless told otherwise with:

        sqlsrv_configure("WarningsReturnAsErrors", 0);
    

    Thanks anyway.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题