使用SQL Server和PHP显示存储过程的结果
我试图使用PHP和SQL server显示存储过程的输出。存储过程是一个使用SQL Server和PHP显示存储过程的结果,php,sql,sqlsrv,Php,Sql,Sqlsrv,我试图使用PHP和SQL server显示存储过程的输出。存储过程是一个SELECT语句。到目前为止,我最终处于显示成功消息的else条件下,但无法显示查询结果。以下是函数: function account_search_sp($account_number,$occupant_code,$name,$address,$bill_code,$utility_code){ global $db; sqlsrv_configure("WarningsReturnAsEr
SELECT
语句。到目前为止,我最终处于显示成功消息的else
条件下,但无法显示查询结果。以下是函数:
function account_search_sp($account_number,$occupant_code,$name,$address,$bill_code,$utility_code){
global $db;
sqlsrv_configure("WarningsReturnAsErrors", 0);
$sql = "EXEC sp_cigar_account_search @AcctNo= ?, @OccupantCode= ?, @Name= ?, @Address= ?, @BillCode= ?, @UtilityType= ?";
$procedure_params = array(
array(&$account_number, SQLSRV_PARAM_IN),
array(&$occupant_code, SQLSRV_PARAM_IN),
array(&$name, SQLSRV_PARAM_IN),
array(&$address, SQLSRV_PARAM_IN),
array(&$bill_code, SQLSRV_PARAM_IN),
array(&$utility_code, SQLSRV_PARAM_IN)
);
$stmt = sqlsrv_prepare($db, $sql, $procedure_params);
$result = sqlsrv_execute($stmt);
if( !$result ) {
//Show errors
echo "Die error <br>";
die( print_r( sqlsrv_errors(), true));
}else{
echo "<br><h3>Success</h3><br>";
sqlsrv_next_result($stmt);
}
return $stmt; }
function account\u search\u sp($account\u number,$account\u code,$name,$address,$bill\u code,$utility\u code){
全球$db;
sqlsrv_配置(“警告返回错误”,0);
$sql=“EXEC sp_circhip_account_search@AcctNo=?,@OccupantCode=?,@Name=?,@Address=?,@BillCode=?,@utilitype=?”;
$procedure_params=数组(
数组(&$account_number,SQLSRV_PARAM_IN),
数组(&$occupant_代码,SQLSRV_参数_IN),
数组(&$name,SQLSRV_PARAM_IN),
数组(&$address,SQLSRV_PARAM_IN),
数组(&$bill_代码,SQLSRV_参数_IN),
数组(&$utility_代码,SQLSRV_参数_IN)
);
$stmt=sqlsrv_prepare($db、$sql、$procedure_参数);
$result=sqlsrv_execute($stmt);
如果(!$result){
//显示错误
回显“模具错误
”;
模具(打印错误(sqlsrv_errors(),true));
}否则{
回声“
成功
”;
sqlsrv_下一个_结果($stmt);
}
返回$stmt;}
例如,如果我在SSMS中以200作为帐号运行存储过程,我将返回数据
我正在使用PHP7.4
感谢您的帮助。如果我需要包含更多信息,请告诉我。如果我正确理解了问题,您需要使用
sqlsrv\u ferch\u array()
或sqlsrv\u fetch\u object()
获取数据:
您到底想输出什么?每行的值是多少?@Zhorov是的。价值观。
<?
function account_search_sp($account_number, $occupant_code, $name, $address, $bill_code, $utility_code) {
global $db;
sqlsrv_configure("WarningsReturnAsErrors", 0);
$sql = "EXEC sp_cigar_account_search @AcctNo= ?, @OccupantCode= ?, @Name= ?, @Address= ?, @BillCode= ?, @UtilityType= ?";
$procedure_params = array(
array(&$account_number, SQLSRV_PARAM_IN),
array(&$occupant_code, SQLSRV_PARAM_IN),
array(&$name, SQLSRV_PARAM_IN),
array(&$address, SQLSRV_PARAM_IN),
array(&$bill_code, SQLSRV_PARAM_IN),
array(&$utility_code, SQLSRV_PARAM_IN)
);
$stmt = sqlsrv_prepare($db, $sql, $procedure_params);
if ($stmt === false) {
echo "Die error <br>";
die( print_r( sqlsrv_errors(), true));
}
if (sqlsrv_execute($stmt) === false) {
echo "Die error <br>";
die( print_r( sqlsrv_errors(), true));
}
echo "<br><h3>Success</h3><br>";
$data = array();
do {
while ($row = sqlsrv_fetch_array($stmt)) {
$data[] = $row;
}
} while (sqlsrv_next_result($stmt));
return $data;
}
?>