title: MongoDB PHP Driver Fails to Connect and Authenticate
body: <p>I have set up for the first time the authentication for MongoDB. I have two users: 'admin', (set as root in the 'admin' database) and 'testUser' which is set up as 'dbAdmin' in the 'testDatabase'.</p>
  
  <p>When I use mongo shell to login using the following command everything works:</p>
  
  <pre><code>mongo -u testUser -p abcd1234 --authenticationDatabase testDatabase
  </code></pre>
  
  <p>On the PHP's end, I have the following code:</p>
  
  <pre><code>&lt;?php
  class DBConnection {
      const HOST = '1.1.1.1';
      const PORT = 27017;
      const DBNAME = 'testDatabase';
      const USERNAME = 'testUser';
      const PASSWORD = 'abcd1234';
      private static $instance;
      public $connection;
      public $database;
  
      private function __construct() {
  
          if (!extension_loaded('mongo')) die("MongoDB is not installed!");
          try {
              $this-&gt;connection = new MongoClient('mongodb://'.self::HOST.':'.self::PORT.'/'.self::DBNAME, array('username' =&gt; self::USERNAME, 'password' =&gt; self::PASSWORD));
              $this-&gt;database = $this-&gt;connection-&gt;selectDB(self::DBNAME);
          } catch (MongoConnectionException $e) {
              throw $e;
          }
      }
  
      static public function instantiate() {
          if (!isset(self::$instance)) {
              $class = __CLASS__;
              self:: $instance = new $class;
          }
          return self::$instance;
      }
  
      public function getCollection($name) {
          return $this-&gt;database-&gt;selectCollection($name);
      }
  
      public function execute($code) {
          return $this-&gt;database-&gt;execute($code);
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Naturally, host (as well as the db name, username and password) are obfuscated. I have verified multiple time that there is not a typo in the credentials. I have also verified that I can connect to the database from a remote shell, similar to how this script connects.</p>
  
  <p>Still, I always get this error:</p>
  
  <blockquote>
    <p>PHP Fatal error:  Uncaught exception 'MongoConnectionException' with
    message 'Failed to connect to: 1.1.1.1:27017: Authentication
    failed on database 'testDatabase' with username 'testUser': auth failed' in
    /var/www/html/wip/include/mongoConnect.php:17 Stack trace:
    0 /var/www/html/wip/include/mongoConnect.php(17): MongoClient->__construct('mongodb://1.1...', Array)
    1 /var/www/html/wip/include/mongoConnect.php(27): DBConnection->__construct()
    2 /var/www/html/wip/migration/migrate.php(85): DBConnection::instantiate()
    3 {main}   thrown in /var/www/html/wip/include/mongoConnect.php on line 17</p>
  </blockquote>
  
  <p>Credentials for both users are in SCRAM-SHA-1.
  Any idea what is causing this connection issue? </p>