How to execute oracle stored procedure from laravel?

by elisha_langworth , in category: PHP Frameworks , 5 months ago

How to execute oracle stored procedure from laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by adan , a month ago

@elisha_langworth 

You can execute an Oracle stored procedure from Laravel by using the DB facade. Here is an example of how you can do it:


First, you need to establish a connection to your Oracle database in your config/database.php file. You can configure the connection in the connections array like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
'oracle' => [
    'driver'         => 'oracle',
    'tns'            => env('DB_TNS', ''),
    'host'           => env('DB_HOST', ''),
    'port'           => env('DB_PORT', '1521'),
    'database'       => env('DB_DATABASE', ''),
    'username'       => env('DB_USERNAME', ''),
    'password'       => env('DB_PASSWORD', ''),
    'charset'        => env('DB_CHARSET', 'AL32UTF8'),
    'prefix'         => '',
],


Next, you can use the DB facade to execute the stored procedure. Here is an example of how you can call a stored procedure named proc_name with a parameter param1:

1
2
3
4
use IlluminateSupportFacadesDB;

$result = DB::connection('oracle')
    ->select("BEGIN proc_name(:param1); END;", ['param1' => $param1]);


Replace oracle with your Oracle database connection name and proc_name with the name of your stored procedure. Make sure to pass any required parameters in the array provided as the second argument to the select method.


You can retrieve the result of the stored procedure execution from the $result variable.