我正在尝试将参数传递给存储过程 该存储过程可以在Management Studio中正常运行,但是请尝试对下面的代码进行大量修改。
返回错误:
FAILED!Array([0] => Array([0] => IMSSP [SQLSTATE] => IMSSP [1] => -14 [code] => -14 [2] =>传递了无效的参数to sqlsrv_execute。[message] =>无效的参数传递给sqlsrv_execute。))
<?php
include("connection.php");
$clerk_name1 = ''; $clerk_name2 = ''; $order1 = ''; $order2 = ''; $part1 = ''; $part2 = ''; $customer1 = ''; $customer2 = ''; $date_from = ''; $date_to = '';
if (!empty($_REQUEST['clerk_name1']) && !empty($_REQUEST['clerk_name2']) && !empty($_REQUEST['order1']) && !empty($_REQUEST['order2']) && !empty($_REQUEST['part1']) && !empty($_REQUEST['part2']) && !empty($_REQUEST['customer1']) && !empty($_REQUEST['customer2']) && !empty($_REQUEST['date_from']) && !empty($_REQUEST['date_to']))
$sql = "SET NOCOUNT ON; {CALL sp_order_activities (@clerk_name1 = ?, @clerk_name2 = ?, @order1 = ?, @order2 = ?, @part1 = ?, @part2 = ?, @customer1 = ?, @customer2 = ?, @date_from = ?, @date_to = ?)}";
$clerk_name1 = $_GET['clerk_name1']; $clerk_name2 = $_GET['clerk_name2']; $order1 = $_GET['order1'];
$order2 = $_GET['order2'];$part1 = $_GET['part1'];
$part2 = $_GET['part2']; $customer1 = $_GET['customer1'];
$customer2 = $_GET['customer2'];$date_from = $_GET['date_from'];
$date_to = $_GET['date_to'];
$stmt = sqlsrv_prepare( $conn, $sql, [
[$clerk_name1, SQLSRV_PARAM_IN],
[$clerk_name2, SQLSRV_PARAM_IN],
[$order1, SQLSRV_PARAM_IN],
[$order2, SQLSRV_PARAM_IN],
[$part1, SQLSRV_PARAM_IN],
[$part2, SQLSRV_PARAM_IN],
[$customer1, SQLSRV_PARAM_IN],
[$customer2, SQLSRV_PARAM_IN],
[$date_from, SQLSRV_PARAM_IN],
[$date_to, SQLSRV_PARAM_IN]
]);
if (!sqlsrv_execute($stmt)) {
echo "execute FAILED!";
die(print_r(sqlsrv_errors(), true));
}
$data = [];
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ){
$data[] = $row;
}
echo json_encode($data);
ob_flush();
flush();
?>