Class 'MongoDB' not found in fatfree (f3) - php

Iv recently been trying to upload my php application from xampp which i have installed on my home machine to a server. Now the code works perfectly on xampp at home and the mongodb driver works as expected, however after migrating it to the LAMP server, the f3 framework throws this error :
Fatal error: Class 'MongoDB' not found in /nfs/fs0/home/dhu/www/fatfree/lib/db/mongo.php on line 107
Internal Server Error
Fatal error: Class 'MongoDB' not found
In reference i looked up the line it is complaining about and its this one :
$this->db=new \MongoDB(new $class($dsn,$options?:array()),$dbname);
And after looking up solutions on stack and other websites they said to check the version of mongo etc installed so i look it up on the php side to see what was enabled and it returns :
PHP INFO ()
PHP Version 5.6.24-0+deb8u1
mongodb
mongodb support enabled
mongodb version 1.1.8
mongodb stability stable
libmongoc version 1.3.5
libbson version 1.3.5
So since mongo is both installed and enabled on the php server im unsure what exactly the issue is with line 107 in the fatfree framework, does anyone have any idea's? Any help would be appreciated.
So after no real solutions been found here im gonna update to see if i can get more help.
Update
Note the server settings can be found here:
http://lamp0.cs.stir.ac.uk/
and the error here:
http://lamp0.cs.stir.ac.uk/~dhu/
The line its referring too is:
$this->db=new \MongoDB(new $class($dsn,$options?:array()),$dbname);
Within the MONGODB library, mongo.php. After looking at various ways to set the DB up and trying to rewrite the setup code nothing seems to work....
Update 2
$manager = new MongoDB\Driver\Manager("mongodb://mydetails:27017");
If i removed the fatfree framework this line does not throw an error during setup which is surprising as i expected it to be unable to find MongoDB\Driver however it had no problem, its main problem seems simply to be that one line in the fatfree framework and im unsure why...

You need to add MongoDB as dependency in the composer.json file of your Fat-Free Framework.
Just add MongoDB to the require dependency list, if it is not there create one like below.
"require": {
"mongodb/mongodb": "^1.0"
},
Then run composer install again. Now you can reference MongoDB classes inside your code.

First install autoload class for mongodb in your project.Then try with below code
$client = new MongoDB\Client("mongodb://localhost:27017");

Related

Quickest way to get Expression Engine v 2.5.5 working with PHP7

A client’s host has recently updated their server to run PHP 7, which has broken their EE 2.5.5. site (“Call to undefined function mysql_connect()”).
I tried upgrading EE to version 2.11.9 but get errors:
Frontend: can’t find safecracker_lib
Control Panel: PATH_MOD not defined in mod_structure.php, fixing this leads down a rabbit hole starting with an error related to not being able to instantiate the pagination class somewhere.
I just need to get the site running until I build a new site, what is the quickest way I can get the site running with PHP 7?
In your config folder there is a file named database.php
change the line:
$db['expressionengine']['dbdriver'] = 'mysql';
to
$db['expressionengine']['dbdriver'] = 'mysqli';
mysql_connect() has been deprecated since PHP 5 and removed in PHP 7 so you cannot use this function or any of the old mysql functions.
You need to upgrade your codebase, or downgrade your PHP version (highly discouraged).
In regards to your missing pagination class, you may not have implemented core classes that were required when upgrading.
Try running on your command line:
php system/ee/eecms upgrade
You can also read the documentation on how to upgrade the codebase for Expression Engine here.

Error and warning connecting MongoDB to PHP using php_mongodb extension

I installed the MongoDB PHP driver on Windows 10 (I'm using WAMP equipped with PHP 5.6.25. following the istructions I found at http://php.net/manual/en/mongodb.installation.windows.php and I installed also the libbson and libmongoc libraries (requested as requirements) as written at http://php.net/manual/en/mongodb.requirements.php.
Then, I added the bin folders of MongoDB, libbson and libmongoc to system path.
However, even if I can see the php_mongodb extension in the extensions list of WAMP, launching phpinfo() the mongo extension doesn't appear with the others.
Furthermore, tryng to connect to my database with
<?php
$mongo=new MongoClient("");
$db=$mongo->galileo;
$collection= $db->items;
print_r("Number of documens: "); ?>
I got the error
Fatal error: Class 'MongoClient' not found in C:\wamp64\www\galileo\index.php >on line 21
At a first look, reading this error, it might seem like that PHP is looking for php_mongodb extension in the uncorrect folder i.e. C:\wamp64\www\galileo\index.php (where the index page of my project is placed) instead of the correct one C:\wamp64\bin\php\php5.6.25\ext where all the extensions are.
But, looking at php log file php_error.log I find also a warning that says:
PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp64/bin/php/php5.6.25/ext/php_mongodb.dll' - Il sistema operativo non pu� eseguire %1.
in Unknown on line 0.
(for not Italian speaking, the phrase after - means the operating system can't execute %1, even if I can't imagine what %1 stands for).
Even using the new class MongoDB\Driver\Manager I get the error
Fatal error: Class 'MongoDB\Driver\Manager' not found in C:\wamp64\www\galileo\index.php on line 21
and the same warning.
Do you notice some error or forgetfulness in the installation process as I described and, if not, do you know how to fix the problem?
The problem is certainly related to WAMP and I think is related to the multiple php.ini in his folders. In fact, in the apache folder you can find a php.ini file that cannot be modified, otherwise nothing works at all; at the same time any changes made to the php.ini file in the php folder seems have no effect except making appear the mongodb extension in the extensions list.
So, I try using XAMPP, as suggested in this video tutorial and it works. Using Composer I was able to install also the PHP library and not only the driver.
you should not use 'MongoClient class' anymore, this extension that defines this class is deprecated. look at here.
instead, you should use MongoDB\Driver\Manager class. please read http://php.net/manual/en/class.mongodb-driver-manager.php.
and the setup must be like this in php:
$mongo = new MongoDB\Driver\Manager("mongodb://localhost:27017");
And if you still use the old class; 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 here.
the last part is from derickr's answer in this issue on github: https://github.com/mongodb/mongo-php-driver/issues/300

CakePHP 3.0 not running on other machines

I've developed a small project on a machine, using CakePHP 3.0, and I need it to run on another machine. I've tried to install it on several other machines.
If I run the composer to install the CakePHP 3.0, then I copy my stuff to overwrite it, the project works. I've tried this on two machines and had no problem so far. If I don't run the composer, and just copy the stuff to the target machine, it gives me the following error. I've tried this on 3 machines, and every machine gives me this:
Fatal error: Class 'Locale' not found in /home/u113681897/public_html/vendor/cakephp/cakephp/src/I18n/I18n.php on line 229
Fatal error: Class 'Locale' not found in /home/u113681897/public_html/vendor/cakephp/cakephp/src/I18n/I18n.php on line 229
I've copied the whole project to this server to test.
I told you this because I thought it has something to do with my problem. The point is that I have to run this on a machine that is not mine, and I can't install composer on it. The /public_html/vendor/cakephp/cakephp/src/I18n/ has files related to internationalization and localization, but my project will never be translated, so a workaround to make the project ignore those files would be enough to solve my problem.
The following code is an excerpt from the (...)/I18n/I18n.php that might be relevant:
<?php
namespace Cake\I18n;
use Aura\Intl\FormatterLocator;
use Aura\Intl\PackageLocator;
use Aura\Intl\TranslatorFactory;
use Cake\I18n\Formatter\IcuFormatter;
use Cake\I18n\Formatter\SprintfFormatter;
use Locale;
class I18n {
// lots of code here
public static function defaultLocale() {
if (static::$_defaultLocale === null) {
static::$_defaultLocale = Locale::getDefault() ?: 'en_US';
// the line above is the Line 229
}
return static::$_defaultLocale;
}
// many code here too
}
I've checked that another file also tries to access this Locale class, but I don't know if there are other files trying to access it as well. Many files from everywhere inside the project tries to access methods from I18n.php. I need it running but I can't figure out how to make it run.
Any help will be greatly appreciated.
As I just found out, prior to CakePHP 3.0, the installation must be done by composer, as stated in the 3.0 migration guide:
CakePHP should be installed with Composer
Since CakePHP can no longer easily be installed via PEAR, or in a shared
directory, those options are no longer supported. Instead you should use
Composer to install CakePHP into your application.
So it won't run on regular free web hosting services.

Phalcon Mongo Class not found error

I attempting to setup Phalcon PHP using a Mongo database connection. I have configured my bootstrap (index.php) file using the following:
// Mongo database connection
$di->set('mongo', function(){
$mongo = new Mongo();
return $mongo->selectDb("phalcon");
}, true);
// Collection Manager
$di->set('collectionManager', function(){
return new \Phalcon\Mvc\Collection\Manager();
});
Whenever I attempt execute an insert fucntion in using this connection, I receive a 500 Internal server error. Now, I have checked my apache server error logs and it states "PHP Fatal error: Class 'Mongo' not found in /var/www/phalcon-mongo/public/index.php on line 17".
I don't know why this request is not processing, according to the documentation given from Phalcon, the connection to mongo DB is setup up as I have displayed above.
If anyone has any advice, please let me know.
i think it's because your installation of Mongo is not valid.
try printing phpinfo() and check if mongo is loaded at all, if not - install it, add to ini files (if you use cli, don't forget to add to cli ini too) and reach the moment, when mongo is fully loaded.
try mongo w/o phalcon. any simple connection/insertation. you can see here: Fatal Error - 'Mongo' class not found that there are problems with apache module version for some people. Try reinstalling different mongo version.
if you can print this out:
echo Phalcon\Version::get();
there should be no problems with phalcon instalation
to validate mongo installation, try any of examples from php.net:
http://www.php.net/manual/en/mongo.tutorial.php
if both installations are valid, then there are problems with your custom code, but before doing anything you have to validate both installations.

Configuring MongoDB + doctrine in Symfony

I was trying to install MongoDB doctrine bundle as written in here
But when I ran the command
$ php bin/vendors install
It throws up the following error:
Fatal error: Call to undefined method
Doctrine\ODM\MongoDB\Configuration::setLoggerCallable()in
C:\wamp\www\Symfony\app\cache\dev\appDevDebugProjectContainer.php on line 245
I have followed the installation instructions to the word (which has not been much anyways...) and i have also double checked my installation... Is there something I am missing here?
Update : A similar problem is mentioned here, but even after following the answer there, i could not successfully configure DoctrineMongoDBBundle.
The latest changes in the Doctrine MongoDB repo have introduces this problem. To stick to a version before this happened, add this line to deps.lock:
doctrine-mongodb 5ccb18231218ce92c9d72295f69bebfe172ef5fb
Well, finally I managed to solve it by adding this to the deps file:
[DoctrineMongoDBBundle]
git=http://github.com/symfony/DoctrineMongoDBBundle.git
target=/bundles/Symfony/Bundle/DoctrineMongoDBBundle
version=origin/2.0
** note the
version=**origin**/2.0
which is different from the previously suggested simple
version=2.0.0 or something similar...
I have a hunch that this problem occurs only on Windows, I hope someone could kindly confirm this.

Categories