Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

In PHP development, use Mongo extension to link MongoDB resources for addition, deletion, modification, query, etc.

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "using Mongo extensions to link MongoDB resources for addition, deletion, modification and query in PHP development". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In PHP development, use Mongo extension to link MongoDB resources for addition, deletion, modification, query and other operations.

When choosing the Mongo extension, there are two official options:

The first kind: https://pecl.php.net/package/mongodb

The second kind: https://pecl.php.net/package/mongo

On the second interface, the official hint is: This package has been superseded, but is still maintained for bugs and security fixes.

The main idea is that the package has been replaced, but still maintains vulnerabilities and security patches, and does not say how long it will be maintained.

Obviously, it is the first one to replace it.

So what's the difference between the two extensions?

Different ways of linking

/ / extension for the first installation: mongo$mongoUrl = "mongodb://127.0.0.1:27017/user_info"; $mongoClient = new MongoClient ($mongoUrl); $mongoDB = $mongoClient- > user_info;$collections = $mongoDB- > listCollections (); foreach ($collections as $collection) {var_dump ($collection);} / / extension for the second installation: mongodb// uses composer for installation (see end for installation) / / composer require mongodb/mongodbrequire 'vendor/autoload.php' / / include Composer's autoloader$mongoUrl = "mongodb://127.0.0.1:27017/user_info"; $mongoClient = new MongoDB\ Client ($mongoUrl); $mongoDB = $mongoClient- > user_info;$collections = $mongoDB- > listCollections (); foreach ($collections as $collection) {var_dump ($collection);}

Release time is different

Mongo 1.6.14 (the latest version) was released on 2016-04-26.

Mongodb 1.2.6 (the latest version) was released in 2017-03-07.

As for when mongo will stop maintenance, there is no specific answer.

Others are different.

May be in the specific use of the process, can be distinguished.

It is said that the two extensions provide completely different classes and interfaces.

Let's go and explore.

Suggestion

The mongo extension is recommended for PHP version 5.x.

Mongodb extension is recommended for PHP version 7.

Of course, PHP5.x can also use mongodb extensions.

However, php7 cannot use mongo extensions.

PHP can install both versions at the same time, as shown below:

PHP manual:

Https://secure.php.net/manual/zh/book.mongo.php

Https://secure.php.net/manual/zh/set.mongodb.php

Install composer

/ / Linux server cd ~ curl-sS https://getcomposer.org/installer | php// is moved to the bin directory mv composer.phar / usr/local/bin/composercomposer-V php// / create a composer.json file {"require": {}} "use Mongo extensions to link MongoDB resources for addition, deletion, modification and other operations in PHP development". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report