title: How do I create a connection class with dependency injection and interfaces?
body: <p>I was reading this SO question:</p>
  
  <p><a href="https://stackoverflow.com/questions/7975174/php-multiple-different-databases-dependency-injected-class">PHP - multiple different databases dependency injected class</a></p>
  
  <p>Top answer.  I understand the concept behind using an Interface here, but I don't know how to use it.  Here is what the top answer said, sorry if I'm not supposed to copy it here:</p>
  
  <p>You should create an interface first for all the DB operations.</p>
  
  <pre><code>interface IDatabase
  {
      function connect();
      function query();
      ...
  }
  </code></pre>
  
  <p>Then have different driver classes implementing this interface</p>
  
  <pre><code>class MySQLDB implements IDatabase
  {
  }
  class PGSQLDB implements IDatabase
  {
  }
  </code></pre>
  
  <p>This way you can easily use dependency injection.</p>
  
  <pre><code>class Test
  {
     private $db;
  
     function __construct(IDatabase $db)
     {
          $this-&gt;db = $db;
     }
  }
  </code></pre>
  
  <p>You can call it as:</p>
  
  <pre><code>$mysqldb = new MySQLDB();
  $test = new Test($mysqldb);
  or
  $pgsqldb = new PGSQLDB();
  $test = new Test($pgsqldb);
  </code></pre>
  
  <p>What I don't understand is how to complete it in the class test and what I am passing to test.  Where is my connection information going?  I was hoping someone would help me complete this for a mysql connection or maybe pdo.</p>