后端开发
网络新概念,云计算、大数据、O2O、电商。。。。
网络新概念,云计算、大数据、O2O、电商。。。。
2017-11-20 16:37:51
sqlserver存储过程中如果有print的变量或字符都需要注释掉,否则会产生01000的错误,另外在存储过程中加入 SET NOCOUNT ON参数
比较完整的调用存储过程的文章:
http://blog.csdn.net/xiangxueping80/article/details/45913459
/*调用sqlserver存储过程返回记录集*/ function get_customer_money($fcompanynumber,$fdeptnumber){ //database host begin $dbhost="172.16.0.1"; $dbuser="sa"; $dbpass=""; $dbname="dbtest"; $connectionInfo = array("UID" => $buser, "PWD" => $dbpass, "Database"=>$dbname,"CharacterSet"=>"utf-8"); $conn = sqlsrv_connect($dbhost, $connectionInfo); $freturnamt = '0'; if($conn) { //echo "connect ok<br>"; //echo "Connection established.\n"; //需要用"{}"括起来,"?"代表存储过程所需要的参数,包括输入和输出的参数 $tsql_callSP = "{call pro_money_query(?,?)}"; $params = array( array($fcompanynumber, SQLSRV_PARAM_IN), array($fdeptnumber, SQLSRV_PARAM_IN) ); $stmt3 = sqlsrv_query($conn, $tsql_callSP, $params); if( $stmt3 === false) { //die(print_r(sqlsrv_errors(), true)); return '-1'; } while($row = sqlsrv_fetch_array($stmt3, SQLSRV_FETCH_ASSOC)){ $freturnamt=$row["famt"]; //print_r($row); } sqlsrv_next_result($stmt3); sqlsrv_free_stmt($stmt3); sqlsrv_close($conn); return $freturnamt; } else { echo "Connection could not be established.\n"; //die( print_r( sqlsrv_errors(), true)); return '-1'; } }