lundi 16 avril 2018

Does laravel create connection with database every single time we run a query?

I wrote following code in my laravel application. This code is fetching data from four different tables and every table has totally different columns.

$response = [];
$response['test1'] = DB::table('test1')
->where('user_id','=',$user->id)
->whereNull('deleted_at')
->get();
$response['test2'] = DB::table('test2')
->where('user_id','=',$user->id)
->whereNull('deleted_at')
->get();
$response['test3'] = DB::table('test3')
->where('user_id','=',$user->id)
->whereNull('deleted_at')
->get();
return  ['success' => true,'data' => $response, 'errors'=> null];

Now just for curiosity, I want to know how this code will run.

  1. How many connections will Laravel create while running the following queries?
  2. If it creates a new connection for every single query then how it will affect my application if my DB server is on a different continent?
  3. And If it creates a single connection then for how much time the connection persists?


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire