数据库开发

网络新概念,云计算、大数据、O2O、电商。。。。

sqlserver的存储过程执行都很正常,就是php获取不到返回的参数,这个问题再调用sql2008r2的时候出现问题,在调用sql2016的时候正常,很奇怪!

参考解决问题的资料:

https://stackoverflow.com/questions/25412675/php-get-return-value-from-mssql-stored-procedure


https://docs.microsoft.com/en-us/sql/connect/php/how-to-retrieve-input-and-output-parameters-using-the-sqlsrv-driver


sqlsrv_next_result($stmt);
echo $outSeq;


        $freturninfo = '                                                                                                                      ';
        //这个地方比较变态,如果定义一个空的字符串$freturninfo='',则执行存储过程的时候返回值字符串比较长会提示字"符串数据,右截断"
        //pro_NewReceiveBill_oper,需要用"{}"括起来,"?"代表存储过程所需要的参数,包括输入和输出的参数
        $tsql_callSP = "{call pro_btob_NewReceiveBill_oper(?,?,?,?,?,?,?,?,?,?)}";
        $params = array(
            array($fopertype, SQLSRV_PARAM_IN),
            array($fordersn, SQLSRV_PARAM_IN),
            array($fpayno, SQLSRV_PARAM_IN),
            array($fpayamt, SQLSRV_PARAM_IN),
            array($fcompanynumber, SQLSRV_PARAM_IN),
            array($fdeptnumber, SQLSRV_PARAM_IN),
            array($fbank, SQLSRV_PARAM_IN),
            array($famt, SQLSRV_PARAM_IN),
            array($fmemo, SQLSRV_PARAM_IN),
            array($freturninfo,SQLSRV_PARAM_INOUT)
        );
        //sqlsrv_query($conn, 'set names GB2312');
        $stmt3 = sqlsrv_query($conn, $tsql_callSP, $params);
        if( $stmt3 === false)
        {
			//echo 'error';
        }
	sqlsrv_next_result($stmt3);  //这个地方是关键点==============
	//echo "info: ".$freturninfo; 		
        sqlsrv_free_stmt($stmt3);
        sqlsrv_close($conn);
        return $freturninfo;