无法从PHP调用存储过程
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法从PHP调用存储过程相关的知识,希望对你有一定的参考价值。
有人可以指出我的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.1SQLserver';
$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);
.........
?>
我忘记了什么......?服务器似乎返回空响应,并且不更新实际记录。
答案
让它工作:
$query1 = "EXEC updateRecord @Record = '$Record', @Status = '$Stat', @Tech = '$Tech', @Date = '$Date', @time = '$time', @Actions = '$Action'";
thanks to this: https://stackoverflow.com/a/44911709
以上是关于无法从PHP调用存储过程的主要内容,如果未能解决你的问题,请参考以下文章