Can't connect to Atlas with PHP

phpinfo:

PHP Version 7.2.24-0ubuntu0.18.04.17

|MongoDB extension version|1.3.4|
|MongoDB extension stability|stable|
|libbson bundled version|1.8.2|
|libmongoc bundled version|1.8.2|
|libmongoc SSL|enabled|
|libmongoc SSL library|OpenSSL|
|libmongoc crypto|enabled|
|libmongoc crypto library|libcrypto|
|libmongoc crypto system profile|disabled|
|libmongoc SASL|enabled|

I try to connect with this code:

try {
    $mdbserver = 'foo.bar.mongodb.net';
    $user = 'username';
    $pw = 'password';

    $client = new MongoDB\Client('mongodb+srv://'.$user.':'.$pw.'@'.$mdbserver.'/?retryWrites=true&w=majority');
    echo(MSG_CLIENT_SUCCESS);
}
catch (Throwable $e) {
    // catch throwables when the connection is not a success
    echo "Captured Throwable for connection : " . $e->getMessage() . PHP_EOL;
}

but I get this error:

Failed to parse MongoDB URI: 'mongodb+srv://username:password@foo.bar.mongodb.net/?retryWrites=true&w=majority'. Invalid URI Schema, expecting 'mongodb://'.

Support for the mongodb+srv URI scheme was added in libmongoc 1.9, which was first included in ext-mongodb 1.4.0. You’ll have to upgrade the extension in order to connect to MongoDB Atlas. On the bright side, the most recent minor version (1.15) still supports PHP 7.2, so you don’t have to run a 5 year old driver version.

Thank you so much for the help. It did work!!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.