ali_254 Posted October 19, 2022 Share Posted October 19, 2022 hi.i installed mongodb and install "driver mongodb for php" from pecl.php.net. when run this code , I am getting the error " Fatal error: Uncaught Error: Class "MongoClient" not found". <?php $m = new MongoClient(); echo "Connection to database successfully"; // select a database $db = $m->examplesdb; echo "Database examplesdb selected"; Quote Link to comment https://forums.phpfreaks.com/topic/315441-fatal-error-uncaught-error-class-mongoclient-not-found/ Share on other sites More sharing options...
requinix Posted October 19, 2022 Share Posted October 19, 2022 Whatever you found that talks about "MongoClient" is out of date. There is no such class - not anymore. https://www.php.net/manual/en/set.mongodb.php 1 Quote Link to comment https://forums.phpfreaks.com/topic/315441-fatal-error-uncaught-error-class-mongoclient-not-found/#findComment-1601786 Share on other sites More sharing options...
ali_254 Posted October 20, 2022 Author Share Posted October 20, 2022 <?php try { // connect to OVHcloud Public Cloud Databases for MongoDB (cluster in version 4.4, MongoDB PHP Extension in 1.8.1) $m = new MongoDB\Driver\Manager('mongodb://localhost:27017'); echo "Connection to database successfully"; // display the content of the driver, for diagnosis purpose var_dump($m); } catch (Throwable $e) { // catch throwables when the connection is not a success echo "Captured Throwable for connection : " . $e->getMessage() . PHP_EOL; } Solved, thanks 1 Quote Link to comment https://forums.phpfreaks.com/topic/315441-fatal-error-uncaught-error-class-mongoclient-not-found/#findComment-1601792 Share on other sites More sharing options...
ali_254 Posted October 20, 2022 Author Share Posted October 20, 2022 10 hours ago, requinix said: Whatever you found that talks about "MongoClient" is out of date. There is no such class - not anymore. https://www.php.net/manual/en/set.mongodb.php Is this class deprecated from PHP version 8? Quote Link to comment https://forums.phpfreaks.com/topic/315441-fatal-error-uncaught-error-class-mongoclient-not-found/#findComment-1601796 Share on other sites More sharing options...
requinix Posted October 20, 2022 Share Posted October 20, 2022 7 minutes ago, ali_254 said: Is this class deprecated from PHP version 8? MongoClient was removed in mongodb 1.0.0. That was back in 2015. 1 Quote Link to comment https://forums.phpfreaks.com/topic/315441-fatal-error-uncaught-error-class-mongoclient-not-found/#findComment-1601798 Share on other sites More sharing options...
ali_254 Posted October 20, 2022 Author Share Posted October 20, 2022 2 hours ago, requinix said: MongoClient was removed in mongodb 1.0.0. That was back in 2015. If I use the "dll" file, is there no need to install the driver using Composer? Quote Link to comment https://forums.phpfreaks.com/topic/315441-fatal-error-uncaught-error-class-mongoclient-not-found/#findComment-1601802 Share on other sites More sharing options...
requinix Posted October 20, 2022 Share Posted October 20, 2022 6 hours ago, ali_254 said: If I use the "dll" file, is there no need to install the driver using Composer? If you install it then there's no need to install it a second time. 1 Quote Link to comment https://forums.phpfreaks.com/topic/315441-fatal-error-uncaught-error-class-mongoclient-not-found/#findComment-1601811 Share on other sites More sharing options...
ali_254 Posted October 21, 2022 Author Share Posted October 21, 2022 Quote In this tutorial, he first downloads the "DLL" file and then downloads it with Composer.Then, to connect to Mango, it is added to the project by Composer. I don't know what codes I should use to connect to the "dll" file Quote Link to comment https://forums.phpfreaks.com/topic/315441-fatal-error-uncaught-error-class-mongoclient-not-found/#findComment-1601831 Share on other sites More sharing options...
ali_254 Posted October 21, 2022 Author Share Posted October 21, 2022 Solved Quote Link to comment https://forums.phpfreaks.com/topic/315441-fatal-error-uncaught-error-class-mongoclient-not-found/#findComment-1601841 Share on other sites More sharing options...
requinix Posted October 21, 2022 Share Posted October 21, 2022 That video is almost 7 years old. Maybe you can try finding something a little more recent? 1 Quote Link to comment https://forums.phpfreaks.com/topic/315441-fatal-error-uncaught-error-class-mongoclient-not-found/#findComment-1601844 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.