Home > Back-end >  How to Install MongoDB and Connect to DB with PHP
How to Install MongoDB and Connect to DB with PHP

Time:12-07

I had Downloaded and installed the mongo dB And it still showing the error

Please tell me how to configure and connect to MongoDB in PHP

CodePudding user response:

<?php
$client = new MongoDB\Client(
    'mongodb srv://<username>:<password>@<cluster-address>/test?retryWrites=true&w=majority'
);
$db = $client->test;

Reference

CodePudding user response:

before you connect you want to add a mongo driver for PHP, then you

[reference][1]
[video reference][2]

<?PHP
    $m = new MongoClient();
    echo "Connection to database successfully";
?>

[1]: https://www.tutorialspoint.com/mongodb/mongodb_php.htm#:~:text=<?-,php // connect to mongodb $m = new MongoClient(); echo,('$set'=>
[2]: https://www.youtube.com/watch?v=wSIQ8n6H9os

  • Related