Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Lumen中的PHP PDO作为返回值调用SQL Server存储过程会出现语法错误_Php_Sql Server_Stored Procedures_Lumen_Freetds - Fatal编程技术网

使用Lumen中的PHP PDO作为返回值调用SQL Server存储过程会出现语法错误

使用Lumen中的PHP PDO作为返回值调用SQL Server存储过程会出现语法错误,php,sql-server,stored-procedures,lumen,freetds,Php,Sql Server,Stored Procedures,Lumen,Freetds,我试图从SqlServer存储过程获取返回值。但它在我的Ubuntu服务器中给出了语法错误,该服务器使用FreeTDS SQLSTATE[HY000]:一般错误:20018“0”附近的语法不正确。 [20018](严重程度15)[(空)] 下面是我的代码: $stateId = 1; $testData = 0; $retVal = 0; $pdo = DB::connection(env('DBCONNECTION'))->getPdo(); $stmt = $pdo->prep

我试图从SqlServer存储过程获取返回值。但它在我的Ubuntu服务器中给出了语法错误,该服务器使用FreeTDS

SQLSTATE[HY000]:一般错误:20018“0”附近的语法不正确。 [20018](严重程度15)[(空)]

下面是我的代码:

$stateId = 1;
$testData = 0;
$retVal = 0;

$pdo = DB::connection(env('DBCONNECTION'))->getPdo();
$stmt = $pdo->prepare('EXEC ? = GetMyCities_sp @StateID = ?, @TestData = ?');
$stmt->bindParam(1, $retVal, \PDO::PARAM_INT,20);
$stmt->bindParam(2, $stateId, \PDO::PARAM_INT);
$stmt->bindParam(3, $testData, \PDO::PARAM_INT | \PDO::PARAM_INPUT_OUTPUT, 20);

$result_status = $stmt->execute();

$resultSet = $stmt->fetchAll(\PDO::FETCH_OBJ);
print_r($resultSet);
echo "<br />";
$stmt->nextRowset();

echo "Return value is ".$retVal;
$stateId=1;
$testData=0;
$retVal=0;
$pdo=DB::connection(env('DBCONNECTION'))->getPdo();
$stmt=$pdo->prepare('EXEC?=GetMyCities_sp@StateID=?,@TestData=?);
$stmt->bindParam(1,$retVal,\PDO::PARAM_INT,20);
$stmt->bindParam(2,$stateId,\PDO::PARAM_INT);
$stmt->bindParam(3$testData,\PDO::PARAM_INT | \PDO::PARAM_INPUT_OUTPUT,20);
$result_status=$stmt->execute();
$resultSet=$stmt->fetchAll(\PDO::FETCH_OBJ);
打印(结果集);
回声“
”; $stmt->nextRowset(); echo“返回值为”。$retVal;

同样的方法在我的windows机器上也能很好地工作。知道代码中有什么错误吗?

IIRC,绑定参数必须是参数,而不是过程名称。是否可以对此进行测试,用存储过程名称替换第一个

$stmt = $pdo->prepare('EXEC your-proc-name = GetMyCities_sp @StateID = ?, @TestData = ?');
$stmt->bindParam(1, $stateId, \PDO::PARAM_INT);
$stmt->bindParam(2, $testData, \PDO::PARAM_INT | \PDO::PARAM_INPUT_OUTPUT, 20);
我已经很长时间没有使用PHP了,但是如果第一次测试成功,您可能可以这样做:

$stmt = $pdo->prepare('EXEC $retVal = GetMyCities_sp @StateID = ?, @TestData = ?');

你看到这个了吗?是的,但我不确定这两个是否完全相同。对我来说,抛出异常时,param位于正确的位置,但在执行时显示语法错误。占位符只能表示值,不能表示关键字/标识符。@marcB很抱歉,我没有理解您的意思。此处,占位符仅与值绑定。不是关键词。不,它不起作用。它再次给出了类似的语法错误。