The PHP documentation for PDO::ATTR_PERSISTENT states:

Persistent connections are not closed when the script is terminated, they are cached and reused when another script requests a connection with the same credentials.

What is called "credentials"?

If there is a connection to the database:

 $dbh = new PDO('mysql:host=localhost;dbname=test;charset=utf8', $user, $pass); 

Connection without specifying a database and encoding will create a new connection or use an already open one?

 $dbh2 = new PDO('mysql:host=localhost', $user, $pass); 

    1 answer 1

    In this case, it does not matter. View Code

     $dbh = new PDO(...); $dbh2 = new PDO(...); 

    will always open two connections. Regardless of what type of connection is used and what parameters are passed.

    I also want to note that if we are talking about access to different databases that are accessible to the same user, then more than one connection is not necessary in this case: you can always choose a database with a standard USE db_name or specify directly in the query through a dot before the name tables.