title: Best way to access config for PDO database class with dependency injection
body: <p>I am learning how to use PDO and writing a Database class for the first time. I have read for a few hours about this subject and found some useful information <a href="https://stackoverflow.com/questions/11514143/php-pdo-mysql-how-to-use-database-connection-across-different-classes">here</a>, <a href="https://stackoverflow.com/questions/6297835/php-and-pdo-class-question">here</a> and <a href="https://stackoverflow.com/questions/18092511/php-how-to-access-pdo-object-from-other-multiple-classes">here</a>.</p>
  
  <p>It seems clear that dependency injection is the right strategy, but I'm not sure on the best way to have the Database class access the configuration details for the database (host, dbname, user, pass).</p>
  
  <p>In the first two examples above, this information is included inside the Database class. However, I usually keep all my global configuration variables inside an external file such as config.php.</p>
  
  <p>In the last example, user 'prodigitalson' adds this comment to his getInstance() method:</p>
  
  <pre><code>// get the arguments to the constructor from configuration somewhere
  </code></pre>
  
  <p>Since the constructor for this Database class includes parameters for the database configuration, I assume that this information is not supposed to be stored in the Database class itself. </p>
  
  <p>So what is the best strategy for accessing the database configuration (which I am currently storing in config.php along with other config variables) from the getInstance() method?</p>
  
  <p>Someone asked <a href="https://stackoverflow.com/questions/3392231/dependency-injection-class-where-to-store-configs">a similar question here</a> but none of the answers really addresses the question, imo.</p>