没有使用PHP从存储过程MSSQL DB接收结果

时间:2016-05-26 09:41:22

标签: php sql-server sql-server-2008 stored-procedures

嗨我有一个问题,我没有收到存储过程的结果,即时通讯使用php和mssql数据库。

我可以在sql server profiler中看到查询,当我在sql server管理工具中运行该查询时,查询正常工作。

当我使用php查询时,我收到以下错误

$session_id = "9999912C8D74"; $patient_id = "9999912C8D74"; $days = 7; $params = array ( array ( $session_id, SQLSRV_PARAM_IN ), array ( $patient_id, SQLSRV_PARAM_IN ), array ( $days, SQLSRV_PARAM_IN ) ); $tsql_callSP = "exec dbo.STOREDPROCEDURECALL @SessId=?, @PatId=?, @days=?"; $stmt3 = sqlsrv_query ( $this->conn, $tsql_callSP, $params ); if ($stmt3 === false) { echo "Error in executing statement 3.\n"; die ( print_r ( sqlsrv_errors (), true ) ); } if( sqlsrv_fetch( $stmt3 ) === false) { die( print_r( sqlsrv_errors(), true)); } $name = sqlsrv_get_field( $stmt3, 1); echo "$name: "; $comment = sqlsrv_get_field( $stmt3, 2); echo $comment; while ( $obj = sqlsrv_fetch_object ( $stmt3 ) ) { var_dump ( $obj ); echo $obj->BGUM . "<br>"; } }

这是我的PHP代码          &#39; if($ this-&gt; conn){

labelled[[0,1,2,..b,-1,-2,-3,..-b],:,:] = 0
labelled[:,[0,1,2,..b,-1,-2,-3,..-b],:] = 0
labelled[:,:,[0,1,2,..b,-1,-2,-3,..-b]] = 0

我在stackoverflow上尝试了大量的解决方案,没有任何工作:-(任何建议都会感激不尽。谢谢。

1 个答案:

答案 0 :(得分:0)

毕竟,答案是在SP中添加SET NOCOUNT ON;

删除此部分:

if( sqlsrv_fetch( $stmt3 ) === false) 
    {
        die( print_r( sqlsrv_errors(), true));
    }

    $name = sqlsrv_get_field( $stmt3, 1);
    echo "$name: ";

    $comment = sqlsrv_get_field( $stmt3, 2);
    echo $comment;

    while ( $obj = sqlsrv_fetch_object ( $stmt3 ) ) {
        var_dump ( $obj );
        echo $obj->BGUM . "<br>";
    }

sqlsrv_fetch_array的帮助下更改此内容(阅读here):

while ($obj = sqlsrv_fetch_array($stmt3, SQLSRV_FETCH_NUMERIC)) {
    echo $obj[0]." ".$obj[1]."<br>"; //I don't know how many columns your SP return
}

sqlsrv_free_stmt( $stmt3);

或者您可以使用列名获取:

while ($obj = sqlsrv_fetch_array($stmt3, SQLSRV_FETCH_ASSOC)) {
    echo $obj['name']." ".$obj['comment']."<br>"; 
}

sqlsrv_free_stmt( $stmt3);