Install MongoDB PHP extension on window, windowmongodb

Source: Internet
Author: User
Tags install mongodb mongodb driver php mongodb

Install MongoDB PHP extension on window, windowmongodb
1. Download

Github provides a pre-compiled php mongodb driver Binary Package (: php_mongo) for the window platform. You can download the version corresponding to php in the actual environment. I set up the environment in PHP version 5.6.11, So download php mongodb driver Binary Package for php_mongo-1.6.8.zip.


There are many dll files with different file names after the file is decompressed. Pay attention to the following issues:
'Thread safe '(Thread security) is run on Apache to use module PHP. If you run PHP In CGI Mode, select the non-thread safe mode ('non-thread safe ').
VC9 is run on the IIS server.

I chose the php_mongo-1.6.8-5.6-vc11.dll, that is, thread-safe, PHP version 5.6, now change the file name to php_cmd.dll and add it to your PHP extension directory (ext ). The ext directory is usually the ext directory under the PHP installation directory.

2. Configuration

Open the php configuration file php. ini and add the following Configuration:

extension=php_mongo.dll

3. Test

Restart the server and access phpinfo through a browser. If the installation is successful, the following types of information will be displayed: 4 \

4. Simple Application

PHP code:

<? Php // mongodb is installed on the local machine and port 27017 is used. $ Client = new MongoClient ("mongodb: // 127.0.0.1: 27017"); // select a database and specify a data table. $ collection = $ client-> test-> persons; // insert data $ array = array ('name' => 'liuruiqun', 'age' => 25, 'address' => array ('vince '=> 'sichuang', 'city' => 'chengdu'); $ ret = $ collection-> insert ($ array ); // query data $ res = $ collection-> findOne (); // print the data var_dump ($ res );

Running result:



Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.