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.