Greetings.
It so happened that in the application two ready-made solutions with github use different ways of working with the same mysql database.

I can get a PDO object from one component, it politely gives it, and the second one supports all possible connection options, but you cannot simply transfer an already prepared PDO object there. So the question is brewing, how rational is it to use in the application two different connections with the database?

By the way, it is a question of RedbeanPHP and Illuminate / database

  • one
    and to fork and add the necessary code? and then another pullrequest to do. - KoVadim

1 answer 1

Nobody forbids to use two different connections to the same database from different components of the application. It is also necessary to bear in mind that upon completion of the script, all connections are released, so you need to think about the "rationality" only if you have an official simultaneous session and the script runs for 10 minutes.

But if you really do not like to keep two connections instead of one, then you can use "permanent" connections.

$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass, array( PDO::ATTR_PERSISTENT => true )); 

Then, when you try to create new connections, the existing ones will be returned.