OOP and connecting to multiple databases using PDO I'm just starting to learn OOP and I've setup a class to handle the database connections and wanted to check if I'm going about this the right way. 

My website is already using PDO for prepared statements but it's procedural code otherwise. The site connects to multiple databases and one of the databases has two connections for separate privileges. 

I have created a Dsn class which contains a method for each connection. My config file instantiates the class and opens all the connections using the methods and passing params where necessary. I'll put the code below but just wanted to check if connecting to multiple databases in this way through a single class follows best practices for OOP.

config.php

$dbh = new Dsn;
$pdo = $dbh-&gt;connnect1Read(NAME1, USER2, PASS2);
$pdo2 = $dbh-&gt;connnect2Write(NAME1, USER1, PASS1);
$pdo3 = $dbh-&gt;connnect3(USER2, PASS2);
$pdo4 = $dbh-&gt;connnect4(USER3, PASS3);
$pdo5 = $dbh-&gt;connnect5(USER4, PASS4);


dsn.php

    class Dsn
{

 private $host = 'localhost';
 private $charset = 'utf8mb4';

 private $dbName1;
 private $userName1;
 private $userPass1;

 private $dbName2 = 'db2';
 private $userName2;
 private $userPass2;

 private $dbName3 = 'db3';
 private $userName3;
 private $userPass3;

 private $dbName4 = 'db4';
 private $userName4;
 private $userPass4;


 private $opt = [
                            PDO::ATTR_ERRMODE            =&gt; PDO::ERRMODE_EXCEPTION,
                            PDO::ATTR_DEFAULT_FETCH_MODE =&gt; PDO::FETCH_ASSOC,
                            PDO::ATTR_EMULATE_PREPARES   =&gt; false,
                      ];


  public function connnect1Read($dbName, $userName, $userPass)
  {
    $this-&gt;dbName1 = $dbName;
    $this-&gt;userName2 = $userName;
    $this-&gt;userPass2 = $userPass;

    $dsn = "mysql:host=" . $this-&gt;host . ";dbname=" . $this-&gt;dbName1 . ";charset=" . $this-&gt;charset . "";
    $pdo1 = new PDO($dsn, $this-&gt;userName2, $this-&gt;userPass2, $this-&gt;opt);

    return $pdo1;
  }

  public function connnect2Write($dbName1, $userName, $userPass)
  {
    $this-&gt;dbName1 = $dbName1;
    $this-&gt;userName1 = $userName;
    $this-&gt;userPass1 = $userPass;

    $dsn = "mysql:host=" . $this-&gt;host . ";dbname=" . $this-&gt;dbName1 . ";charset=" . $this-&gt;charset . "";
    $pdo2 = new PDO($dsn, $this-&gt;userName1, $this-&gt;userPass1, $this-&gt;opt);

    return $pdo2;
  }

  public function connnect3($userName, $userPass)
  {
    $this-&gt;userName2 = $userName;
    $this-&gt;userPass2 = $userPass;

    $dsn = "mysql:host=" . $this-&gt;host . ";dbname=" . $this-&gt;dbName2 . ";charset=" . $this-&gt;charset . "";
    $pdo4 = new PDO($dsn, $this-&gt;userName2, $this-&gt;userPass2, $this-&gt;opt);

    return $pdo3;
  }

  public function connnect4($userName, $userPass)
  {
    $this-&gt;userName3 = $userName;
    $this-&gt;userPass3 = $userPass;

    $dsn = "mysql:host=" . $this-&gt;host . ";dbname=" . $this-&gt;dbName3 . ";charset=" . $this-&gt;charset . "";
    $pdo5 = new PDO($dsn, $this-&gt;userName3, $this-&gt;userPass3, $this-&gt;opt);

    return $pdo4;
  }

  public function connnect5($userName, $userPass)
  {
    $this-&gt;userName4 = $userName;
    $this-&gt;userPass4 = $userPass;

    $dsn = "mysql:host=" . $this-&gt;host . ";dbname=" . $this-&gt;dbName4 . ";charset=" . $this-&gt;charset . "";
    $pdo3 = new PDO($dsn, $this-&gt;userName4, $this-&gt;userPass4, $this-&gt;opt);

    return $pdo5;
  }
}
This is not how things are done in the programming world. You don't write a dozen functions doing the same thing. You write just one function. 

Speaking of OOP, there is no use for it here. Given your class consists of just one method, just make it a function:

function connnect($dbName, $userName, $userPass)
{
    $host = 'localhost';
    $charset = 'utf8mb4';
    $opt = [
                        PDO::ATTR_ERRMODE            =&gt; PDO::ERRMODE_EXCEPTION,
                        PDO::ATTR_DEFAULT_FETCH_MODE =&gt; PDO::FETCH_ASSOC,
                        PDO::ATTR_EMULATE_PREPARES   =&gt; false,
                  ];
    $dsn = "mysql:host=$host;dbname=$dbName;charset=$charset";
    return new PDO($dsn, $userName, $userPass, $opt);
}


and then create your connections:

$dbRead = connnect(NAME1, USER2, PASS2);
$dbWrte = connnect(NAME1, USER1, PASS1);
$db3 = connnect(NAME3, USER2, PASS2);
$db4 = connnect(NAME4, USER3, PASS3);
$db5 = connnect(NAME5, USER4, PASS4);