External Database connection in an Extension: non-existent parameter "dbal.driver.class"

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
barrycarlyon
Registered User
Posts: 851
Joined: Wed Mar 29, 2006 3:46 pm
Location: Manchester
Name: Barry Carlyon
Contact:

External Database connection in an Extension: non-existent parameter "dbal.driver.class"

Post by barrycarlyon » Sat May 19, 2018 1:12 pm

I've been following this thread: viewtopic.php?f=461&t=2248926

Which is probably outdated.

Code: Select all

imports:
    - { resource: parameters.yml }
services:
    dbal.extensions_db:
        class: %dbal.driver.class%
        calls:
            - [sql_connect, [%host%, %user%, %password%, %dbname%, %dbport%, false, true]]
Currently this is resulting in:

Code: Select all

Exception: The service "dbal.extensions_db" has a dependency on a non-existent parameter "dbal.driver.class". Did you mean this: "cache.driver.class"?
And having done some digging and testing and trying a few bits and pieces, I'm unable to find the correct parameter in order to raise a secondary DB connection at this time.

So rather than necro that thread. Heres a new one.

Primary Question

What is the correct services call to make a secondary connection to another DB

Bonus Question for zero points.

Is it better or preferential to:

Code: Select all

services:
    somename:
        class: someclass
        arguments:
            - @config
            - @controller.helper
            - @dbal.conn
Or

In your class:

Code: Select all

        global $phpbb_container;
        $this->db = $phpbb_container->get('dbal.conn');
IE inject DB via services of globalling the phpbb_container?
Last edited by barrycarlyon on Sat May 19, 2018 1:49 pm, edited 1 time in total.
Barry Carlyon

User avatar
GanstaZ
Registered User
Posts: 333
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: External Database connection in an Extension

Post by GanstaZ » Sat May 19, 2018 1:44 pm

First option is the way to go. Second option is used in module classes, but may change if module system will be re-written.

User avatar
barrycarlyon
Registered User
Posts: 851
Joined: Wed Mar 29, 2006 3:46 pm
Location: Manchester
Name: Barry Carlyon
Contact:

Re: External Database connection in an Extension

Post by barrycarlyon » Sat May 19, 2018 1:45 pm

GanstaZ wrote:
Sat May 19, 2018 1:44 pm
First option is the way to go. Second option is used in module classes, but may change if module system will be re-written.
Well thats the bonus question answered… what about the primary question :-D
Barry Carlyon

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 2813
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: External Database connection in an Extension: non-existent parameter "dbal.driver.class"

Post by kasimi » Sat Jun 09, 2018 8:18 am

Maybe this code helps: https://github.com/phpbb/phpbb/blob/rel ... #L538-L549

Instead of $this->config_php_file you can use the global $phpbb_config_php_file.

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: Toxyy and 10 guests