简体   繁体   English

Laravel和存储过程SQL

[英]Laravel and stored procedures SQL

I have a stored procedure that client has made. 我有一个客户端制作的存储过程。 Now I have to access it and process data in my laravel app. 现在,我必须访问它并在laravel应用中处理数据。

I have no problems with connecting to SQL but the problems starts when passing in parameters. 我没有连接到SQL的问题,但是问题在传入参数时开始。

Here is my code: 这是我的代码:

$connections = DB::connection('sqlsrv')
    ->select(EXEC [stored].[procedure].[here] $param1, $param2);

The error I got back is: The active result for the query contains no fields 我得到的错误是:查询的活动结果不包含任何字段

I have searched for many hours in forums and here is what I have found: 我在论坛上搜索了许多小时,以下是我发现的内容:

$connections = DB::connection('sqlsrv')
->select(DB::raw('EXEC [stored].[procedure].[here] $param1, $param2'));

Error I got back is: The active result for the query contains no fields. 我得到的错误是:查询的活动结果不包含任何字段。

I have installed SQL driver and OBDC driver. 我已经安装了SQL驱动程序和OBDC驱动程序。

Any help would be much appreciated 任何帮助将非常感激

Don't know if this will help but this answer suggests you put your DB::raw around just the params instead of the EXEC stored.proc.name . 不知道这是否有帮助,但是这个答案建议您将DB :: raw放在参数周围,而不是EXEC stored.proc.name

So instead of 所以代替

 $connections = DB::connection('sqlsrv')->select(DB::raw('EXEC [stored].[procedure].[here] $param1, $param2'));

Try 尝试

 $connections = DB::connection('sqlsrv')->select('EXEC stored.proc.name' . DB::raw($param1, $param2));

OK. 好。 So I found out the issue. 所以我找出了问题所在。

It turns out the client sent me over a variable with xml. 事实证明,客户端通过xml发送了一个变量给我。 As far as I figured out from Microsoft docs then you can t pass xml as a varable because if you call the SP from an application it is gonna pass it as an array and application can t parse xml into array directly. 据我从Microsoft文档中了解到的那样,您不能t pass xml as a varable because if you call the SP from an application it is gonna pass it as an array and application can直接将xml解析为数组。 You have to do it on your own. 您必须自己做。

What can be done instead is to pass xml as a value of an array and then take it from there. 相反,可以做的是将xml作为数组的值传递,然后从那里获取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM