0

I am making a mongodb connection but when I access my config.php it give me the error

"mongodb driver not found".

config.php

try { $connectionString = "mongodb://" . $m4-live-mongodb; 
$options = array( 'username' => 'hello', 'password' => 'world' ); 
// adding support for php 5.4 and uppper
 if (($mv = phpversion('mongo')) === false) 
    {
     throw new Exception("Mongo db driver not found");
    }
       elseif (version_compare($mv, '1.3.0', '<')) 
        { 
            $mongo = new Mongo($connectionString, $options); 
        } else 
        {
         $mongo = new MongoClient($connectionString, $options); 
        } $mC = $mongo->$db->$collection; var_dump($mC); 
       } catch (exception $e) 
       { 
        echo $e->getcode().'<hr>'; echo $e->getmessage();
         } 
1

The command pecl list lists the installed packages in the default channel. In the below code block the default channel is pecl.php.net

The command pecl search mongodb searches for the latest stable version of mongodb. Results of pecl search mongodb :

pecl search mongodb
Retrieving data...0%
Matched packages, channel pecl.php.net:
=======================================
Package Stable/(Latest) Local
mongodb 1.3.4 (stable)        MongoDB driver for PHP

When you are checking for mongodb version 1.3.0 you are getting the message Mongo db driver not found because the latest stable version of mongodb is not 1.3.0, it is 1.3.4. Check if the version of mongodb that you have installed is 1.3.4, and if so change your code accordingly.

According to your comment, you are using mongodb, not mongo. In line 4 of your PHP code change phpversion('mongo') to phpversion('mongodb').

  • yes it is 1.3.4.i change the code accordingly but still getting the same error. @karel – Muhammad Zaman Dec 21 '17 at 11:22
  • You are using mongodb, not mongo. In line 4 of your PHP code change phpversion('mongo') to phpversion('mongodb'). – karel Dec 21 '17 at 11:35
  • after changing that i am getting this error "localhost is currently unable to handle this request." @karel – Muhammad Zaman Dec 21 '17 at 11:42
  • I think the localhost is currently unable to handle this request. error is an error in the PHP code, not an Ubuntu software error. Try asking about it at Stack Overflow. – karel Dec 21 '17 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.