Kaustubh
1 year ago

Undefined Index Driver

Posted 1 year ago by Kaustubh

Hi, I have two different database and i connect to another database to get the data. It works fine but when i continuously press refresh it throws Undefined Index Driver. below is my code

CONNECTION TO ANOTHER DATABASE

  // Disconnect old connection and connect to other database
  $dm = app("Illuminate\Database\DatabaseManager");
  $dm->disconnect();
  $model = Config::set("database.connections.pgsql", [
      'driver'    => 'pgsql',
      'host'      => '127.0.0.1',
      'port'      => '5432',
      'database'  => 'jobseeker',
      'username'  => 'postgres',
      'password'  => 'root',
      'charset'   => 'utf8',
  ]);
  DB::setDefaultConnection('pgsql');
  DB::reconnect($model);
  //End

RE CONNECTION TO CURRENT DATABASE

    // Disconnect old connection and connect to original database
    $model = Config::set("database.connections.".env('DB_CONNECTION'), [
        'driver'    => env('DB_CONNECTION'),
        'host'      => env('DB_HOST'),
        'port'      => env('DB_PORT'),
        'database'  => env('DB_DATABASE'),
        'username'  => env('DB_USERNAME'),
        'password'  => env('DB_PASSWORD'),
        'charset'   => 'utf8',
    ]);
    DB::setDefaultConnection(env('DB_CONNECTION'));
    DB::reconnect($model);
    //End

The reason behind the error is, i called credential from env file and on refresh it sometime dosent get value from env. I dont want to use hardcore values to reconnect to current database. Is there any solution for this

Please sign in or create an account to participate in this conversation.