I have installed and successfully connected to MongoDB from my local machine. When I ran the site which uses it from my localhost it has no problem connecting to it, but when I upload the folder to a FTP client and connect to a web hosting and domain it says MongoClient class not found.
Should I change something in the config.php file? Now it looks like this:
<?php
$conn = new MongoClient();
$data = $conn->db;
?>
Install Mongodb Extension with:
apt-get install php-pear php5-dev
pecl install mongo
Related
I want to install the php-extenstion ibm_db2.so with the following command :
pecl install ibm_db2
During the installation, pecl asks for the DB2 Installation Directory. I already used this command on an other server where an db2 is installed, so there was no problem, giving him the db2 directory.
But now I need to install the extension on a server without a local installed db2. There is a website intended to run on this server with a connection to the database-server, so I need the php-commands provided by the ibm_db2.so.
Pecl still wants an installation directory. But, as I mentionend, the db2 resides on an other server.
Is it crucial to have the db2 on the same server? Or do I just use an incorrect command for installing?
If I leave the field empty
and just press enter, the installation fails.
I am trying to install MongoDB on my computer running Mac OS X 10.11 (El Capitan).
My Apache + PHP configuration was already working correctly.
I installed MongoDB and PHP drivers for MongoDB through MacPorts:
sudo port install mongodb
sudo port install php55-mongodb
Installation ran correctly.
I added mongodb.so file to the extensions loaded in the php.ini file:
extension=/opt/local/lib/php55/extensions/no-debug-non-zts-20121212/mongodb.so
When I run phpinfo() function in php file, mongodb extension seems to be loaded correctly:
I tried to test my connexion by initializing a MongoClient instance:
<?php
$mongoDB = new MongoClient();
var_dump($mongoDB);
?>
Unfortunately, I got a HTTP ERROR 500, and I got the following line in my Apache logs:
PHP Fatal error: Class 'MongoClient' not found in ...
Did I make something wrong ?
On most of site I saw you need to add the extension mongo.so and not mongodb.so in your php.ini.
If it's not solved your problem, I recommand you to install MongoDB Drive with PELC.
Run command line:
$ sudo pecl install mongo
And add this line to your php.ini:
extension=mongo.so
Doc php.net Mongo Installation
Finally found a solution to my problem.
As #neverpanic and #Zagonine made me understand, php-mongodb and php-mongo are not the same extension.
If you want to use old PHP driving classes, you should use php-mongo package instead of the very new php-mongodb.
Trying to install latest php-mongo extension, I had an other problem related to OpenSSL. To bypass it, I installed an old version of php-mongo extension:
sudo /usr/local/pear/bin/pecl install mongo-1.5.8
Hopefully it will help someone else.
I have mongo server install and the mondo php extension enable:
Why am I still getting this error:
Fatal error: Class 'MongoClient' not found in ...
My code:
// connect to mongodb
$m = new MongoClient();
var_dump($m);
How I install mongo server:
`$ sudo apt-get install mongodb-server`
How I install mongo client:
`$ sudo apt-get install php-pear php5-dev`
`$ sudo pecl install mongodb`
Add extension=mongodb.so at the end of php.ini
Restart Apache sudo /etc/init.d/apache2 restart
What have I missed?
Try this:
Run below command in your project using terminal:
composer require mongodb/mongodb
Add below code in your php file:
require 'vendor/autoload.php';
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->db->collection;
Go through this documentation for more details.
Hope this may helpfull
Open your Ubuntu Software Centre and search for mongo driver.
Select MongoDB Database Driver php5-mongo and install it.
Restart Apache: sudo /etc/init.d/apache2 restart
I have no idea what mongodb is installed for!!!
The MongoClient class was provided with the now deprecated mongo driver. You installed the mongodb driver, which provides the Manager class:
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
var_dump($manager);
The mongodb driver provides a minimal API for core driver functionality, but no classes such as MongoClient. The MongoDB PHP library provides a high-level abstraction around this lower-level driver, e.g. a Client class, and can be installed with composer.
I'm trying to connect to Mongolab db server, but I get this error:
Fatal error: Class 'MongoClient' not found in /home/viviane/public_html/sk/zizi/head.php on line 33
I suspect it is related to the PHP Mongo Driver, but I don't know how. If I try to connect to a remote mongodb server
$uri = "mongodb://dzyasser:dzyasser#ds049624.mongolab.com:49624/serverdb";
$options = array("connectTimeoutMS" => 30000);
$connection = new MongoClient($uri, $options );
So why am I still getting this error when I'm trying to connect to a remote Mongodb server (Mongolab)?
Its look like you don't have MongoDB PHP extension in your system.
Try to install MongoDB PHP extension in order to solve your problems with the MongoClient class. This is how I setup MongoDB PHP extension in OS X.
Get MongoDB extension from PECL
$ sudo pecl install mongodb
Make a copy of php.ini.default
$ sudo cp /etc/php.ini.default /etc/php.ini
Put this line on php.ini than save
extension=mongodb.so
Check the installation using this command
php --re mongodb
Or create simple php document that contain phpinfo() function
If you get problem with writing the extension, please read this post.
I assume, the Mongo driver is installed and loaded.
If so, since the error message says the MongoClient class cannot be found, it might be caused by a namespace used in your script. If so, try
$connection = new \MongoClient($uri, $options );
Regardless of whether you are connecting locally or remotely, it seems PHP requires the mongo DB service to be running on your server. So install it like so:
a) Install mongodb service
$ sudo apt-get install -y mongodb
b) Add the php drivers if they are missing:
$ sudo apt-get install php5-dev php5-cli php-pear -y
$ sudo pecl install mongo
c) Then open your php.ini file and add to it the extension line "extension=mongo.so":
$ sudo vi /etc/php5/apache2/php.ini
> extension=mongo.so
d) Then restart apache
$ sudo service apache2 restart
Disclaimer: This example was tried on Ubuntu 14.04 LTS with Apache web-service and PHP5 installed. If your installation is different, follow the same approach but issue appropriate commands. If you have no access to SSH or sudoer privileges, contact someone who can help you do this.
I've installed Apache2 with php5 support and everything works there. I've installed PostgreSQL and am able to connect to it using the terminal and execute SQL statements.
PROBLEM: I can't get a working connection between my php scripts and the PostgreSQL database. I have installed the php5-pgsql packaged from the repositories, but the connection just won't work.
I get the following error message:
PHP Fatal Error: Call to undefined function pg_connect() in /var/www/[myfile].php on line [X]
How do I enable support for PostgreSQL connections in PHP5 in ubuntu 11.04?
EDIT: Checked phpinfo() and found no entries for PostgreSQL. I don't know why that is so, I DID install php5-pgsql package for ubuntu 11.04.
Here is what worked: I installed phppgadmin from the Ubuntu repositories. Not only does this make a nice tool available for me now, it also installed the needed packages for php to connect to postgresql.
After that, it was all in the connection parameters. It wouldn't connect to the database on the local server until I defined the connection host, port, database, user, and password in that order in pg_connect().
I still don't know why installing php5-pgsql on my own didn't enable PostgreSQL connections from php. Any input on this would be helpful.
Install the php5-pgsql package solves the problem. (depending on the version ... php4-pgsql for php4)
apt-get install php5-pgsql
Remember to restart Apache.
/etc/init.d/apache2 restart
--Note that it might be hard if you do not administer your server.
Currently, I am using Ubuntu 16.04 LTS.
Me too was facing same problem while Fetching the Postgress Database values using Php so i resolved it by using the below commands.
Mine PHP version is 7.0, so i tried the below command.
apt-get install php-pgsql
Remember to restart Apache.
/etc/init.d/apache2 restart
Below is my code , might be someone get benefited :
- testdb.php
<html>
<body>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
Friend ID
</td>
<td>
Name
</td>
</tr>
<?php
$db = pg_connect('host=localhost dbname=postgres user=postgres password=root port=5432');
$query = "SELECT * FROM account"; //account is name of table
$result = pg_query($query);
if (!$result) {
echo "Problem with query " . $query . "<br/>";
echo pg_last_error();
exit();
}
while($myrow = pg_fetch_assoc($result)) {
printf ("<tr><td>%s</td><td>%s</td></tr>", $myrow['id'], htmlspecialchars($myrow['name']));
}
?>
</table>
</body>
</html>
The only conclusion I can come up with is that phppgadmin installed all of the needed packages to make PHP5 connect to PostgreSQL. I have looked at the dependencies, and I believe that I either didn't install them at all or didn't install them correctly.
I require no more help in this arena, as I have a working setup and know at least one method of getting to that point.