0

I started a Symfony 4.3 project and I have to work with an Oracle 11g database for this project. However, the documentation of Symfony does not offer enough lucidity on the subject, especially the configuration to connect to an oracle database. It's almost 3 days since I tried to solve this problem, but I found nothing.

//.env

DATABASE_URL=mysql://user:pass@127.0.0.1:3306/the_spacebar
DATABASE_CUSTOMER_URL=pdo_oci://user:pass@localhost:1521/XE

//doctrine.yaml

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                # configure these for your database server
                driver: 'pdo_mysql'
                server_version: '5.7'
                charset: utf8mb4
                default_table_options:
                    charset: utf8mb4
                    collate: utf8mb4_unicode_ci

                url: '%env(resolve:DATABASE_URL)%'

            customer:
                # configure these for your database server
                driver: 'pdo_oci'
                server_version: ~
                charset: AL32UTF8
                default_table_options:
                    charset: AL32UTF8
                    collate: ~

                url: '%env(resolve:DATABASE_CUSTOMER_URL)%'

    orm:
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    Main:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Main'
                        prefix: 'App\Entity\Main'
                        alias: Main
            customer:
                connection: customer
                mappings:
                    Customer:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Customer'
                        prefix: 'App\Entity\Customer'
                        alias: Customer

The error was:

An exception occurred in driver: SQLSTATE[HY000]: pdo_oci_handle_factory: ORA-12505: TNS:listener does not currently know of SID given in connect descriptor
(ext\pdo_oci\oci_driver.c:634)

SaschaM78
  • 4,376
  • 4
  • 33
  • 42
  • 1
    Hello everyone, I started a Symfony 4.3 project and I have to work with an Oracle 11g database for this project. However, the documentation of Symfony does not offer enough lucidity on the subject, especially the configuration to connect to an oracle database. It's almost 3 days since I tried to solve this problem, but I found nothing. Thank you for helping me. – Maxime Yannick Epoh Jul 16 '19 at 14:37

1 Answers1

0

I solved my problem as follows:

// .env
DATABASE_URL=mysql://user:pass@127.0.0.1:3306/dbname
DATABASE_CUSTOMER_URL=//user:pass@localhost:1521/XE

// doctrine.yaml
doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                # configure these for your database server
                url: '%env(DATABASE_URL)%'
                driver: 'pdo_mysql'
                server_version: '5.7'
                charset: utf8mb4

            customer:
                # configure these for your database server
                url: '%env(DATABASE_CUSTOMER_URL)%'
                driver: 'pdo_oci'
                server_version: ~
                charset: AL32UTF8

    orm:
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    Hand:
                        is_bundle: false
                        type: annotation
                        dir: '% kernel.project_dir%/src/Entity/Main'
                        prefix: 'App\Entity\Main'
                        Alias: Main
            customer:
                connection: customer
                mappings:
                    Customer:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Customer'
                        prefix: 'App\Entity\Customer'
                        alias: Customer
  • note, however, that I work with two databases in my project (MySQL and Oracle 11g). You will certainly have noticed by looking at my configurations. – Maxime Yannick Epoh Jul 18 '19 at 08:15