I want to use Mongo DB with php, so for that I have installed the driver and its showing here as well in phpinfo()
The problem is when I try to connect it, I get Fatal error.
Fatal error: Uncaught Error: Class 'MongoDB\Client' not found
Here is how I am connecting
$mongo = new \MongoDB\Client('mongodb://user:xxx!#00.00.00.00/chat');
try
{
$dbs = $mongo->listDatabases();
print_r($dbs);
}
Here is how I installed extension sudo apt-get install php7.0-mongodb
Also I followed this http://php.net/manual/en/mongodb.tutorial.library.php
Any help!
\MongoDB\Client belongs to the mongo-php-library which is different from mongo-php-driver
in another words, the library is using the driver,
so after installing the mongo-php-driver you need to perform another operation by installing the library using composer
composer require mongodb/mongodb
or even by cloning it from github
git clone https://github.com/mongodb/mongo-php-library.git
Related
I have an issue with connecting php(valet) and MongoDB. I tried to install MongoDB with pecl and command sudo pecl install mongodb and brew install mongodb and all time I get some errors during the install process:
In file included from /private/tmp/pear/temp/mongodb/src/MongoDB/Cursor.c:18: /opt/homebrew/Cellar/php#8.0/8.0.17/include/php/ext/spl/spl_iterators.h:151:4: error: unknown type name 'pcre_cache_entry' pcre_cache_entry *pce; ^ 1 error generated. make: *** [src/MongoDB/Cursor.lo] Error 1 ERROR: make' failed`.
But when I run mongo --version I get:
and I install MongoDB Compass and as you can see, I can connect to the database and write into it:
But when I try out to install laravel package jenssegers/mongodb I get these errors: I tried with --ignore-platform-req=ext-mongodb flag but then it install package but it didn't work, I get this error: Error: Class "MongoDB\Driver\Manager" not found.
Finally, I find out a great package that helps me in this! This repo saves me a ton of time and debugging! Thank you shivammathur!
Hey I also had the same problem. A good alternative is to also follow with this article if you want to stick with pecl https://freek.dev/2151-fixing-the-dreaded-pcre2h-file-not-found-error-when-installing-imagick
I am trying to install the mongoDB extension for PHP with MAMP so I can potentially access my MongoDB server, and as far as I can tell, I have done everything right, yet I am still getting errors.
I have the MongoDB extension installed - I can tell because:
$sudo pecl install mongodb
pecl/mongodb is already installed and is the same as the released version 1.5.3
install failed
Also my phpinfo shows this:
Also I have included the following:
var_dump(extension_loaded('mongodb'));
echo phpversion('mongodb')."\n";
which have returned:
/Applications/MAMP/htdocs/mongo.php:35:boolean true
1.5.3
I also have:
$ composer require mongodb/mongodb
Using version ^1.4 for mongodb/mongodb
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
phpinfo tells me my php.ini file is here:
And i have added to that:
extension=mongodb.so
In my PHP file I have the following:
require 'vendor/autoload.php'; // include Composer's autoloader
$m = new MongoDB\Driver\Manager("mongodb://localhost:27017");
//$m = new MongoDB\Client("mongodb://localhost:27017");
echo "connected successfully";
// select a database
$db = $m->bob;
echo "database selected";
If I try the MongDB/Client option, I get the following error:
Fatal error: Uncaught Error: Class 'MongoDB\Client' not found in /Applications/MAMP/htdocs/mongo.php on line 61
If I try the MongoDB/Driver option, I get the following error:
Notice: Undefined property: MongoDB\Driver\Manager::$bob in /Applications/MAMP/htdocs/mongo.php on line 52
A var_dump of MongoDB\Driver etc. gives the following:
/Applications/MAMP/htdocs/mongo.php:38:
object(MongoDB\Driver\Manager)[3]
public 'uri' => string 'mongodb://localhost:27017' (length=25)
public 'cluster' =>
array (size=0)
empty
Is there anything I could be missing?
have you added extension=mongodb.so to your php.ini file ?
that is the only information i do not see listed here.
When I run:
composer global required “fxp/composer-asset-plugin:^1.3.1”,
It's report an error like this:
PHP Fatal error: Uncaught Error: Call to undefined method Composer\Package\RootPackage::getConfig()
Check your composer version is latest; if not, upgrade your composer.
Note: If you are in Ubuntu, and you use sudo apt install composer, plz remove it, install use curl or widget install again.
If your composer version is already the latest, plz use sudo
Use this:
sudo composer global require "fxp/composer-asset-plugin:^1.3.1"
I've got this error when launching a php worker on Iron.io :
PHP Fatal error: Class 'PDO' not found in /mnt/task/...
My PHP script just call the native PDO extension like this :
$db = new PDO (...);
Anybody know if there's a known problem with the docker image iron/php and the PDO extension ?
Thank you.
Try to add php-pdo package into your docker image.
Example of installing php-pdo package via Dockerfile:
FROM iron/php
...
RUN apk add php-pdo
...
I am trying to install on my local machine the following project connect which is using symfony2.
I did perform the following commands:
cd myWebDirectory
git clone git://github.com/dsyph3r/connect
git submodule update --init
When I try to call the following page from my localhost I get the following error:
http://localhost/~myName/connect/web/app_dev.php
Server error
If I look to the logs file of apache I read:
PHP Fatal error: require_once():
Failed opening require
'/Users/myName/Sites/connect/app/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php'
How should I install the vendor?
What I did miss?
You forgot to install the vendor ("third party") libraries.
php bin/vendor install
Update: It's a while ago, since I wrote this and it's not valid anymore (for new(er) projects). Since 2.1 it uses Composer
php composer.phar install