Reputation:
I just can't seem to find any clear instructions on how exactly you do that for PHP 7 running on a machine with Windows 7 installed. I tried a couple of online tutorials, but nothing seems to have worked out for me so far. It's possible that some of you may have had an experience similar to mine and it would be absolutely wonderful if you could share that experience with me: specifically, what exactly you did in order to to get this issue resolved.
Here's what I did:
I downloaded the latest dll library for PHP 7 (mongodb-1.1.2.tgz) from here: PECL :: Package :: mongodb :: 1.1.2, placed the file php_mongodb.dll from the archive into the ext directory where I keep my PHP installation, added the line extension=php_mongodb.dll to the php.ini file (after all these steps, Apache was restarted, of course). The section for mongodb does show up as a result of running the phpinfo() function:
And now I'm trying to run this simple script:
<?php
$connection = new MongoClient();
?>
And what I get back is the following error (I have broken the lines a little 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
Upvotes: 5
Views: 9095
Reputation: 53538
MongoDB offers its own driver, with installation instructions on how to set it up, after which you'll have to use the the MongoDB Driver API, rather than the now obsolete MongoClient way of connecting. If phpinfo()
shows the mongodb extension working, then you should be able to connect to it using the updated syntax:
$client = new MongoDB\Driver\Manager("mongodb://localhost:....");
Upvotes: 3