在 symfony 4.3 项目中连接到 oracle 11g 数据库

问题描述 投票:0回答:1

我启动了一个 Symfony 4.3 项目,并且该项目必须使用 Oracle 11g 数据库。然而,Symfony 的文档在这个主题上没有提供足够的清晰度,尤其是连接到 Oracle 数据库的配置。我尝试解决这个问题已经快三天了,但什么也没发现。

//.env

DATABASE_URL=mysql://user:[email protected]: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

错误是:

驱动程序中发生异常:SQLSTATE[HY000]: pdo_oci_handle_factory: ORA-12505: TNS:listener 当前不知道连接描述符中给出的 SID
(ext\pdo_oci\oci_driver.c:634)

symfony oracle11g
1个回答
0
投票

我解决了我的问题如下:

// .env
DATABASE_URL=mysql://user:[email protected]: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
© www.soinside.com 2019 - 2024. All rights reserved.