Tuesday, March 14, 2017

Laravel mysql multiple operations with one DB instance

As far as I understand, each DB:: in Laravel (I use 5.2, if that matters) basically opens new connection and closes it when operation is finished.

The question is, is there any possibility to create one DB instance and do n operations using it? Something like native php, where you open connection and close it manually after everything is done.

Like

$conn = DB;
$users = $conn->table('users')->get();
$bills = $conn->table('bills')->lists('id');
/* something happens */
unset($conn);

Or something of this type.



via Yawning Milk

Advertisement