Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of PHP and MongoDB

Shulou Source: shulou.com Published: 2022-06-03 06:21:51 11月16日 Update

This article mainly shows you "what is the use of PHP and MongoDB". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "what is the use of PHP and MongoDB?"

A brief introduction to MongoDB

MongoDB (named from "humongous") is a scalable, high-performance, open-source, schema-free, document-oriented database that combines the advantages of document database, key-value pair storage and relational database. Official site: http://www.mongodb.org/ Magi MongoDB Features:

Document-oriented storage (JSON-like data schema is simple and powerful)

Dynamic query

Full index support, extended to internal objects and embedded arrays

Query record analysis

Fast, on-the-spot update

Efficient storage of binary large objects (such as photos and videos)

Replication and failover support

Auto-Sharding automatic sharding supports cloud-level scalability

MapReduce supports complex aggregation

Business support, training and consulting

Second, install MongoDB

It is very easy to install MongoDB, just download the compressed package to extract the run command, download address: http://www.mongodb.org/downloads, this article is the windows platform, MongoDB run command: > bin/mongod. Tip: first of all, you need to create a folder to store data. The default directory for storing data in MongoDB is / data/db/ (or c:\ data\ db). Of course, you can also change it to a different directory. Just specify-- dbpath parameter, eg:

> bin/mongod-- dbpath=d:\ mgdata\ db

Install the MongoDB PHP extension

Download the PHP extension: http://github.com/mongodb/mongo-php-driver/downloads according to your own version of PHP, prompt:

1. VC6 is suitable for Apache and VC9 is suitable for IIS

2. Thread safe is suitable for PHP in module operation mode, and Non-thread safe is suitable for CGI operation mode.

Modify php.ini, add: extension=php_mongo.dll, restart the Web server.

4. Related examples of PHP testing and MongoDB

1. Connect to the Mongo server

The copy code is as follows:

The copy code is as follows:

2. Specify the database and dataset name (table name)

The copy code is as follows:

The copy code is as follows:

3 、 CRUD

The copy code is as follows:

The code is as follows:

4. Close the connection

The above is all the content of this article "what is the use of PHP and MongoDB?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Data code database storage support host password user name useful server port service run content document article command multiple object method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia MySQL vpn Shulou Information