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.
Related
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
I have few controllers in my zf2 project which work perfectly in the browser using apache and via command line.
However, I recently installed MongoDb so I can store some data using the driver found in (http://php.net/manual/en/set.mongodb.php)
My issue is, when I try to access the driver via controller + browser, I get the following message error in my apache logs :
PHP Fatal error: Class 'MongoDb\Driver\Manager' not found.
'MongoDb\Driver\Manager' is the namespace for this Driver.
If I execute some other controllers via command line, MongoDb works correctly.
Does anyone know why is this happening? I cannot see the issue :(
Thank you
I found that my php.ini was pointing to mongo.so instead of mongodb.so
That fixed the issue
http://php.net/manual/en/mongodb.installation.manual.php
Thank you for your help
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");
I'm probably doing something silly here but I've been trying to install the mongodb php client on my windows VM running WAMP for a while and I've gotten nowhere.
I'm running WAMP 64 bit with PHP 5.4.3. I downloaded the 1.3.2RC1 zip from here and I extracted the php_mongo-1.3.2RC1-5.4-vc9.dll file into wamp/bin/php/php5.4.3/ext and then edited the php.ini file to include the new extension.
I restart WAMP and everything is fine, then when I try and use some of the code from the php mongo driver tutorial it says the MongoClient class cannot be found:
Fatal error: Class 'MongoClient' not found in C:\wamp\www\mongo\test.php ...
The code is simple but for completeness I'll include it:
<?php
$m = new MongoClient("the-connection-string-im-using");
?>
Am I missing something? Should I just be able to create a new instance of the MongoClient like above or do I need to do something else?
Cheers
James
I figured it out - I was using the wrong php.ini file. I should have been using the one in the apache directory (C:\wamp\bin\apache\apache2.2.22\bin).
Silly.
I just finished to install Ingres on my server(only the client part, to connect to an existing ingres server), I just added the php_ingres module.
Now php recognize my module, so I tried to connect my self to several existing servers, but I always a
Unable to connect to database (Hostname here)
But with this I can't find what is wrong?? ingres error? Php driver? Credentials? ...?
What can I do to isolate these problem?
Most likely it's a user credentials issue. To see the actual error message use the following code:
$connection = ingres_connect(.....);
if (!is_resource($connection))
{
trigger_error(ingres_errno()." - ". ingres_error(),E_USER_ERROR);
}
You might also want to take a look at http://community.ingres.com/wiki/Ingres_with_Apache_on_Debian_Etch which outlines the setup steps for Ingres, PHP, Apache and Debian/Ubuntu.