How to install the MongoDB driver for PHP 7 on Windows 7?

I just can’t find clear instructions on exactly how you do it for PHP 7 running on a computer with Windows 7. I tried a couple of online lessons, but so far nothing has worked out for me. Perhaps some of you may have had an experience similar to mine, and it would be absolutely wonderful if you could share this experience with me: specifically, what exactly did you do to solve this problem.

Here is what I did:

I downloaded the latest dll library for PHP 7 (mongodb-1.1.2.tgz) here: PECL :: Package :: mongodb :: 1.1. 2 , put the php_mongodb.dll file from the archive into the ext directory, where I continue to install PHP, added the line extension = php_mongodb.dll to the php.ini file (after all these steps, Apache was restarted, of course). The mongodb section appears as a result of running the phpinfo () function:

enter image description here

And now I am trying to run this simple script:

<?php $connection = new MongoClient(); ?> 

And I will return to the following error (I broke the lines a bit for better readability):

 Fatal error: Uncaught Error: Class 'MongoClient' not found in C:\Apache24\htdocs\test2.php:3 Stack trace: #0 {main} thrown in C:\Apache24\htdocs\test2.php on line 3 
+5
source share
1 answer

MongoDB offers its own driver with installation instructions on how to configure them, after which you will have to use the MongoDB API , and not the now obsolete MongoClient connection method. If phpinfo() shows that the mongodb extension is working, you can connect to it using the updated syntax :

 $client = new MongoDB\Driver\Manager("mongodb://localhost:...."); 
+4
source

Source: https://habr.com/ru/post/1242143/


All Articles