如何用口才(Laravel)调用存储过程? [英] How to call Stored Procedure with Eloquent (Laravel)?

查看:77
本文介绍了如何用口才(Laravel)调用存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档中没有提到如何使用雄辩的语法在laravel中的MYSQL中调用存储过程的标准过程.

There is no standard procedure mentioned in documentation that how to call a stored procedure in MYSQL in laravel with Eloquent syntax.

我的意思是有什么办法可以借助雄辩的语法在mysql中调用存储过程

I mean is there any way to call stored procedure in mysql with help of eloquent syntax like

$result = StoredProcedures::my_custom_procedure(param1, param2);
return view('welcome')->with('result',$result);

是否有任何方法可以使用纯精通的语法(纯精通的方式)从存储过程中调用和获取结果.

Is there any way to call and fetch results from stored procedures with pure eloquent syntax(purely eloquent way).

谢谢.强烈建议举一些小例子.

Thanks. Small examples are highly encouraged .

推荐答案

您不能雄辩地调用存储过程.但是,您可以按照以下样式使用查询生成器方法.

You cannot call stored procedure with eloquent. However you can use query builder approach in the following style.

首先将以下名称空间导入控制器文件或您要调用存储过程的文件中.

first import the following namespaces on top of the controller file or in the file where you want to call the Stored Procedure.

use Illuminate\Support\Facades\DB;
use Doctrine\DBAL\Driver\PDOConnection;

然后您可以调用存储过程,如下所示,

then you can call the stored procedure like below,

$queryResult = $db->prepare('call searchAttendance(?,?,?,?,?)'); 
$queryResult->bindParam(1, $start_date); 
$queryResult->bindParam(2, $end_date); 
$queryResult->bindParam(3, $nurseRoles,PDOConnection::PARAM_STR); 
$queryResult->bindParam(4, $leaveTypesDayOffIds,PDOConnection::PARAM_STR); 
$queryResult->bindParam(5, $leaveTypesVactionIds,PDOConnection::PARAM_STR); 
$queryResult->execute(); 
$results = $queryResult->fetchAll(PDOConnection::FETCH_ASSOC); 
$queryResult->closeCursor(); 
return $results;

参考:单击此处

这篇关于如何用口才(Laravel)调用存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆