无法从PHP调用存储过程

时间:2017-12-17 03:28:58

标签: php sql-server sql-server-2012

有人可以指出我的php代码在mssql中调用存储过程有什么问题。以下sql查询在mssql studio中工作正常:

EXEC updateRecord 'Record','Closed','Jon','query test4','',''

这是我用来尝试调用updateRecord的PHP代码:

<?php
 $Record = $_POST['record'];
 $Stat = $_POST['Status'];
 $Tech = $_POST['Tech'];
 $Action = $POST['Action'];
 $Date = date("Y/m/d");
 $time = date("G:i:s");
 //connect to sql
 $hostname = '127.0.0.1\SQLserver';
 $options = array('Database'=>'CallHistory', 'CharacterSet' => 'UTF-8');
 $conn = sqlsrv_connect($hostname, $options); 
 if(!is_resource($conn))
 { 
 echo 'Could not connect: ';
 var_dump(sqlsrv_errors(SQLSRV_ERR_ALL)); 
 exit(0);
 }

 //    echo "Success";
 //    sqlsrv_close($conn);

 // DB queries

 if (empty($_POST['record']) && empty($_POST['Statut'])&&empty($_POST['Tech']) && empty($_POST['Action']))
 {
 echo "CHoose at least one";
 }
else
{
$query1 = "exec updateRecord $Record,$Stat,$Tech,$Action,$Date,$time";
}
$ask = sqlsrv_query($conn, $query1);
sqlsrv_fetch($ask);
.........
?>

我忘了什么......? 服务器似乎返回空响应,并且不更新实际记录。

1 个答案:

答案 0 :(得分:0)

让它发挥作用:

$query1 = "EXEC updateRecord @Record = '$Record', @Status = '$Stat', @Tech = '$Tech', @Date = '$Date', @time = '$time', @Actions = '$Action'";

thanks to this: https://stackoverflow.com/a/44911709