Closed kindaniel closed 7 years ago
you need to specifiy each connection under config/database.php
like here:
'connections' => [
'first' => [
'driver' => 'oracle',
'tns' => env('DATABASE_TNSNAME', 'RACNAME'),
'service_name' => env('DB_SERVICE_NAME', 'SERVICENAME'),
'host' => env('DB_HOST', ''),
'port' => env('DB_PORT', '1521'),
'username' => env('DATABASE_USER', ''),
'password' => env('DATABASE_PASSWORD', ''),
'database' => env('DB_DATABASE', ''),
'charset' => env('DB_CHARSET', 'AL32UTF8'),
'prefix' => env('DB_PREFIX', ''),
'prefix_schema' => env('DB_SCHEMA_PREFIX', ''),
'options' => [
PDO::ATTR_PERSISTENT => true
],
],
'second' => [
'driver' => 'oracle',
'tns' => env('DATABASE_TNSNAME', 'RACNAME'),
'service_name' => env('DB_SERVICE_NAME', 'SERVICENAME'),
'host' => env('DB_HOST', ''),
'port' => env('DB_PORT', '1521'),
'username' => env('DATABASE_USER', ''),
'password' => env('DATABASE_PASSWORD', ''),
'database' => env('DB_DATABASE', ''),
'charset' => env('DB_CHARSET', 'AL32UTF8'),
'prefix' => env('DB_PREFIX', ''),
'prefix_schema' => env('DB_SCHEMA_PREFIX', ''),
'options' => [
PDO::ATTR_PERSISTENT => true
],
],
then later in your code you can use:
DB::connection('first')->select ....
Thank you for you answer. But i want this users and password dynamically...
have a look online this is not specific to laravel-oci8!
https://lukevers.com/2015/03/25/on-the-fly-database-connections-with-laravel-5 https://laracasts.com/discuss/channels/tips/set-up-dynamic-database-connection-globally
Hi Kindanial,
try to change the configs like that :
config([
'database.connections.oracle.host' => $host,
'database.connections.oracle.port' => $port,
'database.connections.oracle.username' => $username,
'database.connections.oracle.password' => $password,
]);
\DB::purge('oracle');
because, the package merge the config from oracle.php to databases.php file. and use them from there.
Good luck.
Summary of problem or feature request
How i make an alternative connection, passing user and password for every connection?
Code snippet of problem
I tryed to make that, but it not works..
{ public function login(Request $request){
System details