There are tons of questions on this topic, but none of them have worked for me. I originally had the mongodb driver installed (and working) using
sudo pecl install mongo
however according to the pecl output this has been deprecated and replaced with
sudo pecl install mongodb
So I installed that, changed mongo.ini to load extension=mongodb.so instead of mongo.so (as instructed to by the output of the above pecl command) . When I load my phpinfo() page it shows that it is loaded
mongodb version 1.0.0
mongodb stability stable
libmongoc version 1.2.0
libbson version 1.2.0
However, when I try to use MongoClient in my PHP page, I get the following error:
Fatal error: Class 'MongoClient' not found in /srv/www/site/functions.php on line 500
I have exhausted all of the 'similar questions' suggested when creating this question, as well as google searches. So I'm hoping someone has some first-hand experience with fixing this because I feel like I'm out of options.
Turns out the class names have changed in the new driver. So MongoClient not existing is a valid error.
new MongoDB\Driver\Manager is the replacement for MongoClient
Related
When executing the following PHP code:
$m = new MongoClient("mongodb://localhost:27017");
I get the following error:
Fatal error: Class 'MongoClient' not found in (...)
MongoDB extension seems properly installed (I copied php_mongodb.dll to ext folder and updated php.ini).
PHP seems to confirm that the extension is running properly as the following code confirms it is loaded:
echo extension_loaded("mongodb") ? "loaded\n" : "not loaded\n";
Also, phpinfo() shows that mongodb extension has been loaded.
UPDATE: my problem is still not solved.
phpinfo() clearly shows that the driver is loaded:
But I am still receiving the same fatal error.
TL;DR
The class MongoClient is part of the legacy PECL package mongo but not anymore of the up-to-date mongodb package.
And since you have the mongodb extension installed, and not the mongo one, this is why you are getting the error
Fatal error: Class 'MongoClient' not found
On MongoDB PHP driver github repo, the release note about the version 1.0.0, is suggesting developers to use MongoDB\Driver\Manager instead of MongoClient
Changes from our legacy mongo extension
Most significantly, the legacy driver's MongoClient, MongoDB, and
MongoCollection classes have been obsoleted by the
MongoDB\Driver\Manager class, which is the new gateway for connecting
and executing queries, commands, and write operations.
Source:: https://github.com/mongodb/mongo-php-driver/releases/tag/1.0.0
So, here is the replacement class documentation and the snippet of code that should replace yours :
$m = new MongoDB\Driver\Manager("mongodb://localhost:27017");
As the documentation is prompting it, the class is deprecated.
Warning This extension that defines this class is deprecated. Instead,
the MongoDB extension should be used. Alternatives to this class
include:
MongoDB\Driver\Manager
Source: http://php.net/MongoClient
From what I read on their github repository release history, the class you are trying to use have been obsoleted since the version of mongodb 1.0.0, so, on the version 1.6.0 you are, this class is not even part of the dll anymore.
That is confirmed by this issue on their github
derickr commented on Apr 16
MongoClient is a class from the old legacy
driver and is not supposed to be available in this one. The new driver
has \MongoDB\Driver\Manager, and, the accompanying library has
\MongoDB\Client.
You either need to install the old legacy extension (pecl install
mongo) and use PHP 5.x, or update your code to use this new driver's
classes as the old driver is not available for PHP 7. There is an
upgrade guide at
http://mongodb.github.io/mongo-php-library/upgrade-guide/
Source: https://github.com/mongodb/mongo-php-driver/issues/300#issuecomment-210820288
Another way, as suggested by the MongoDB member quoted here above is to use this pecl extension: https://pecl.php.net/package/mongo instead of https://pecl.php.net/package/mongodb but please also notice the warning there stating:
This package has been superseded, but is still maintained for bugs and security fixes.
MongoDB(mongo-php-library) and MongoClient(ext-mongo) are different extensions. MongoClient extension is deprecated. If you want to use MongoClient(ext-mongo) related classes, use a wrapper like this one;
https://github.com/mitsh/mongo-php-adapter
Adapter to provide ext-mongo interface on top of mongo-php-library
You don't need to change anything on your project. Just install and include it with composer.
I am trying to configure MongoDB on the AWS server, but when I try to make an API call, I get the following error:
Fatal error: Class 'MongoDB\Driver\Manager' not found in /srv/www/api/releases/20160912135146/vendor/mongodb/mongodb/src/Client.php on line 56
I have done the following:
Install mongodb, following the instructions here -> install mongodb community edition on ubuntu
installed the php mongodb driver using pecl install mongodb
added extension=mongodb.so to php.ini at etc/php5/cli/php.ini
Started the mongodb service
on the server, I can enter the mongo console with $ mongo
What am I missing here, Please?
PS: the API is developed using Phalcon
I finally found a solution to this. Apparently, the apache server uses a special php.ini file, different from etc/php5/cli/php.ini. This file is located in etc/php5/apache2/php.ini. After installing the mongodb driver using pecl install mongodb, your extension should go in etc/php5/apache2/php.ini i.e add extension = mongodb at the end of etc/php5/apache2/php.ini. Good luck
I have a fresh Ubuntu 12.04 installation with a basic web server setup including pecl and OAuth; However, when I run a simple index file (as shown below) I am getting a fatal error:
PHP Fatal error: Class 'OAuth' not found in /var/www/index.php on line 2
Here is my file:
<?php
$oAuth = new \OAuth(CONSUMER_KEY, PRIVATE_KEY);
Obviously the consumer/private keys are my actual keys.
Now I have checked phpinfo() and OAuth is definitely in there. I have it set in my php.ini. I have restarted Apache.
When I run pecl list
Installed packages, channel pecl.php.net
Package Version State
oauth 1.2.3
stable pecl_http 1.7.6 stable
extension_loaded('oauth') // returns true
there's no oAuth in php -m either
Any ideas why I am still getting class not found? I hope it's not something dumb I am missing :)
Cheers guys.
I'm attempting to get the link shortening PHP scripts YOURLS working on my basic web server running Lubuntu 12.04.
I have a MySQL database created and PHP5 installed. When I attempt to access the administration interface for YOURLS in a browser, I am presented with the following message:
Fatal Error: ezSQL_mysql requires mySQL Lib to be compiled and or linked in to the PHP engine
I'm very new to MySQL and PHP, so I don't know how to approach this problem. Could you point me in the right direction on this?
(For a quick guide to setting up YOURLS, you can see this video to get the general idea.)
You need to ensure that the MySQL extension is loaded into PHP.ini, and has been compiled into PHP as well.
Install mysql-devel and php-mysqli packages
yum install mysql-devel php-mysqli
Names can change a bit as Ernest show's in his answer.
If you have installed your php server and mysql through yum, try to use yum to search for the relevant package.
For example, if you used "yum install php55", try "yum search php55", then look for something like "php55-mysqld". If found, install it "yum install php-mysqld". That will install the required module for PHP to interact with your mysql.
Installing all php packages and its dependencies worked for me.
yum install php-*
finnaly i Found the solution
just change this line > class ezSQL_mysql extends ezSQLcore in ez_sql_mysql.php
to class ezSQL_mysqlx extends ezSQLcore
:)
I get this error when i try to run following command
sudo pecl install mongo
Error:
...php_mongo.c:22:10: fatal error: 'php.h'
file not found
#include <php.h>
^
1 error generated.
make: *** [php_mongo.lo] Error 1
ERROR: `make' failed
I am new to MAC, please help me to resolve this and get Mongo Working with PHP.
I have installed MacPorts and autoconf
It seems, that you did not install the xampp "Developer Package", required to build additional php extension. You can download the "Developer Package" from:
http://www.apachefriends.org/en/xampp-macosx.html#849
This has already been answered.
Please follow the processes outlined in this answer - Install PECL on Mac OS X 10.6.
I followed the process outlined here http://akrabat.com/php/setting-up-php-mysql-on-os-x-10-7-lion/, referenced by the above Stackoverflow link and the process for install pear, followed by pecl and subsequently -
sudo pecl install mongo
works perfectly on OSX Lion.
You may need to modify the extensions in /etc/php.ini, however, this is explained in the output after you install the php mongo driver.
It took me the whole day to find this answer, I had tried everything, but this worked finally:
sudo C_INCLUDE_PATH=/usr/local/opt/openssl/include /Applications/XAMPP/xamppfiles/bin/pecl install mongodb
I found this article very helpful. Saved a lot of time after I wasted a lot of time to check other links. I did for MAMP and think will work for XAMPP too.
The thing is MAMP does not ship with all PHP sources to compile pecl mongo file and create mongo.so. All what you need is download php for respective version you are using. I was using php version 5.6.10. I checked php.net site that was having 5.6.13 version. I downloaded sources for this version from PhP.net. Executed "sudo pecl install mongo" again and it worked.