I just tried the suggested connection and I got a failure.
$client = new MongoDB\Client(
'mongodb+srv://USER:PASSWORD@CLUSTER/test?retryWrites=true&w=majority'
);
$db = $client->test;
Could do with some help working out what the issue is.
I have seen several different versions of mongo usage in php which makes it a little confusing.
Also, I couldn’t find a clear link from php 7.4 to mongo driver version. Because I saw a list of other version numbers of the mongo php version. E.g https://docs.mongodb.com/drivers/php under compatibility.
autoload.php is a conventional name for a file which loads a bunch of other php files.
PHP packages typically come with an autoload.php file.
Composer, the tool that installs the MongoDB PHP library on top of PHP’s own MongoDB driver, installs all the packages you install via Composer in a directory called vendor. It’s just like npm in Javascript where everything is installed in a project subdirectory called node_modules.
So typically for PHP + MongoDB you:
make sure the PHP driver mongodb.so is installed and called out in your php.ini files for web and for cli
create your project directory
use Composer to install MongoDB’s PHP Library in your project directory, which results in you having a ./vendor subdirectory of your project
Then, in your program code, require_once ./vendor/autoload.php which loads all the modules Composer installed in your ./vendor subdirectory of your project.