Connecting to a MongoDB Database Server in PHP

After installing the MongoDB database, use the following code to connect to the MongoDB database.

$connection = new Mongo();

The above code connects to the database using default credentials.i.e host is localhost and port is 27017.

To explicitly connect to a remote host where MongoDB is housed, use the following syntax.

$connection = new Mongo( "172.20.10.8:65018" );

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.