Search code examples
phpsymfonydoctrineoci8oid

Connect to an oracle database with doctrine using the OID LDAP


Is it possible to connect to an Oracle database with doctrine using the Oracle Internet Directory (OID) to retrieve the database IP? I can't find any documentation.

Thanks.


Solution

  • First of all, with Doctrine you should use oci8 PHP driver if you want to connect to a Oracle database (whether it's fully supporting your use case I can't tell).

    Second you can simply set your env variable from outside, e.g. first add to your respective ´config.yml´the following line below your imports section:

    imports:
    - { resource: readEnvParams.php }
    

    then create a ´readEnvParams.php´ file in the same folder and first do whatever is necessary to look up the information in the OID and once you have it (e.g. in a variable called $oid), set your parameters:

    $oid = functionToConnectToOIDandRetrieveInfo(OidConnection); //pseudo code
    
    $container->setParameter('database_host', $oid->host);
    $container->setParameter('database_port', $oid->port);
    $container->setParameter('database_name', $oid->name);
    $container->setParameter('database_user', $oid->username);
    $container->setParameter('database_password', $oid->password);
    

    Important (update):

    It's important to understand that when e.g. IP changes using this approach you'll probably have to restart your Symfony application or find another way to reflect the changed IP in running Symfony container.

    If you don't have any fallback for your dynamic IP and no timeout for the OID connection configured your Symfony application either takes forever to start up usefully or doesn't start up at all as no database connection can be established (e.g. when OID is not available).