We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Latest INVO commit

Hi everyone, in the latest version of invo's example how can i add a new connection to database?

Thx Francesco



85.5k

you want to add a 2nd connection, or you want to update the existing one ?

if you need a second connecting, specify the case so the example can be more meaningfull

Hi Izo, thank you for reply!

I want to add a 2nd connection in services.php file and use it in the model (initialize) with setConnectionService. In this version the registration services has done via "class Services extends \Base\Services". I have seen more example with the FactoryDefault DI to set 2nd connection but i don't know how to set with class services.

Thx in advance F.



85.5k

https://forum.phalcon.io/discussion/6927/how-to-use-phalconmvcmodelsetconnectionservice

https://github.com/phalcon/invo/blob/master/app/library/Base/Services.php

so you create a new function here https://github.com/phalcon/invo/blob/master/app/Services.php


 protected function initSharedMyDb2(../*check those i am not sure what u will get here*/)
    return new connection ... 
});

MyModel  {
    public function initialize() 
    {
        $this->setConnectionService('myDb2');
    }
}