Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two connections to Postgres and MongoDB PHP 5.4 #38

Closed
rbianchi opened this issue Sep 11, 2013 · 2 comments
Closed

Two connections to Postgres and MongoDB PHP 5.4 #38

rbianchi opened this issue Sep 11, 2013 · 2 comments

Comments

@rbianchi
Copy link

Hi Jens,

In our application (Laravel4) use two connections to Postgres databases and MongoDB.
Using PHP 5.3 we had no problems, but using PHP 5.4.9 have a problem with the instance of the connection to the DB you are getting 'jenssegers/mongodb/src/Jenssegers/Mongodb/Model.php'. I do not understand why it is that you are getting the connection to the Postgres database in 5.4 but work in 5.3.
We tested the PHP Mongo client 5.4 on a standalone application and it works.

The exception is:

       {"error""type":"ErrorException","message":"Argument 1 passed to Jenssegers\\Mongodb\\Builder::__construct() must be an instance of Jenssegers\\Mongodb\\Connection, instance of Illuminate\\Database\\PostgresConnection given, called in /vendor\/jenssegers\/mongodb\/src\/Jenssegers\/Mongodb\/Model.php on line 186 and defined","file":"/vendor\/jenssegers\/mongodb\/src\/Jenssegers\/Mongodb\/Builder.php","line":37}}

In my case I have defined:

Provider:

      'Jenssegers\Mongodb\MongodbServiceProvider'

Alias of the Laravel Eloquent Model:

      'Eloquent' => 'Illuminate\Database\Eloquent\Model',

Example of a Jenssegers model:

      use Jenssegers\Mongodb\Model as Eloquent;

      MongoData class extends Eloquent {
           protected $ collection = 'data';
      }

And finally,
The connections to the DB:

      'default' => 'pgsql'

      'mongodb' => array (
         'driver' => 'mongodb',
         'host' => 'localhost',
         'port' => 27017,
         'username' => 'user',
         'password' => 'password',
         'database' => 'database'
     )

     'pgsql' => array (
         'driver' => 'pgsql',
         'host' => 'localhost',
         'port' => 5432,
         'database' => 'database',
         'username' => 'user',
         'password' => 'password',
         'charset' => 'utf8',
         'prefix' =>'',
         'schema' => 'public',
     )
@jenssegers
Copy link
Contributor

If you use pgsql as the default driver, you will need to tell your mongodb model to use the mongodb connection. You do this by setting the connection attribute.

@rbianchi
Copy link
Author

Yes! thanks Jean
It works!

Just do not understand why this is not so in PHP 5.3, but that is another problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants