简体   繁体   English

如何创建存储过程Laravel

[英]How to create stored procedure laravel

Hi I've been looking around for some kind of how to guide for stored procedures in Laravel but can't find any so far. 嗨,我一直在寻找某种如何在Laravel中指导存储过程的方法,但到目前为止找不到任何方法。 My issue is basically I have a huge list of parameters that I need to send to the stored procedure called InsertNewApplicant but I'm not sure how to build the query. 我的问题基本上是我有一个庞大的参数列表,需要将其发送到称为InsertNewApplicant的存储过程,但不确定如何构建查询。

This is all I have so far, I'm not sure where I chose which database to send it to or how to make the connection to that database. 到目前为止,这就是我所拥有的全部,我不确定我在哪里选择了将数据库发送到哪个数据库或如何建立与该数据库的连接。

Any help would be greatly appreciated 任何帮助将不胜感激

 $result = DB::select('call InsertNewApplicant(?????????????????????????)',
                    array($firstName, $middleName, $addressLine_1, $addressLine_2, $postCode, $landline, $mobile, $email,
                    $DOB, $maritalStatus, $industry, $occupation, $jobTitle, $selfEmployed, $selfAssessment, $workHome,
                    $ownTransport, $companyVehicle, $paySubs, $otherIncome, $printForms, $marketingUs, $marketingOther,
                    $agreedTNCs, $TNCVersion, $CampaignSource));

Here's my two databases - I need to send this data to the sqlserv database so I'm not sure what to do 这是我的两个数据库-我需要将此数据发送到sqlserv数据库,所以我不确定该怎么做

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', 'SECRET'),
    'port' => env('DB_PORT', 'SECRET'),
    'database' => env('DB_DATABASE', 'SECRET'),
    'username' => env('DB_USERNAME', 'SECRET'),
    'password' => env('DB_PASSWORD', 'SECRET'),
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix' => '',
    'strict' => false,
    'engine' => null,
],
'sqlsrv' => array(
    'driver' => 'sqlsrv',
    'host' => ' AN IP ADDRESS', // Provide IP address here
    'database' => 'SECRET',
    'username' => 'SECRET',
    'password' => 'SECRET',
    'prefix' => '',
),

Your first task is to configure your application to connect to the database that your stored procedure is in. There is plenty of documentation on the Laravel website that will guide you towards how to do this: https://laravel.com/docs/5.1/database 您的第一个任务是配置您的应用程序以连接到存储过程所在的数据库。Laravel网站上有大量文档,可指导您执行此操作: https ://laravel.com/docs/5.1 /数据库

A quick clue is to look inside your app/config/database.php file. 快速提示是查看您的app/config/database.php文件。 It should be fairly obvious what to do once you look at that file. 当您查看该文件后,应该做的很明显。

Once you've configured your database, make sure to select the correct one using the DB::connection() method. 配置数据库后,请确保使用DB::connection()方法选择正确的DB::connection() In your case, you would want to do: $conn = DB::connection('sqlsrv') to get the connection. 在您的情况下,您需要执行以下操作: $conn = DB::connection('sqlsrv')以获取连接。

Once you have added your database connection configuration, you should call your stored procedure by calling the DB::select() method. 添加数据库连接配置后,应通过调用DB::select()方法来调用存储过程。 Just remember to include commas between each of the parameter placeholders (question marks): 只需记住在每个参数占位符(问号)之间包括逗号:

$conn = DB::connection('sqlsrv');
$result = $conn->select('call InsertNewApplicant(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
  [
    $firstName, $middleName, $addressLine_1, $addressLine_2, $postCode, 
    $landline, $mobile, $email, $DOB, $maritalStatus, $industry, 
    $occupation, $jobTitle, $selfEmployed, $selfAssessment, $workHome, 
    $ownTransport, $companyVehicle, $paySubs, $otherIncome, 
    $printForms, $marketingUs, $marketingOther, $agreedTNCs, 
    $TNCVersion, $CampaignSource
  ]
);

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

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