douliaopan1419 2016-05-04 10:17
浏览 107

无法使用symfony2连接数据库oracle

what i need

  • i need to connect oracle database with symfony2.

  • i have checked by php -m

    • oci8
    • pdo_odbc

    • odbc

here is the link i follow https://gist.github.com/johnkary/6481664

a.)config.yml

Doctrine Configuration

 doctrine:
dbal:
    default_connection:   default
    connections:
        default:
            driver:   "%database_driver%"
            host:     "%database_host%"
            port:     "%database_port%"
            dbname:   "%database_name%"
            user:     "%database_user%"
            password: "%database_password%"
            charset:  "%database_charset%"

b.) parameter.yml

  # If connecting via SID
 parameters:
database_driver:   oci8
database_host:     abc
database_port:     '1521'
database_name:     test
database_user:     aa
database_password: aa
database_charset:  AL32UTF8
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: zzzz

c.)services.orcale.yml

 services:
acme.doctrine.dbal.events.oracle_session_init.listener:
    class: %doctrine.dbal.events.oracle_session_init.class%
    tags:
        - { name: doctrine.event_listener, event: postConnect }
acme.doctrine.dbal.oracle_platform.type_mapping.listener:
    class: Acme\MisBundle\Listener\OracleDoctrineTypeMappingListener
    tags:
        - { name: doctrine.event_listener, event: postConnect }
  • then run symfony database cmd

     php bin/console doctrine:database:create
    

error:

 cannot create database test for connection named default.
 notice: undefined index dbname
  • i have googled a day but i think there are few developer who works with symfony2 and oracle.

  • i had made simple php script that works to test connections

    $userName = ""; $password = ""; $dtabasePort = "1521"; $serverName = "";
    
    $databaseName = "testingdb";
    $c = oci_connect($userName, $password, '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = host)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = ) (SID =)))');
    
     print_r($c);
    

output

       Resource id #3

tsnames.ora

    test=

       (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = sss)(PORT = 1521))
          (CONNECT_DATA = (SID = test))
         )
  • i have worked sf3 and mysql but im new to oracle thats why i don"t knew how to connect oracle db with symfony.

  • please give some solution where i have done wrong.

  • Can anyone suggest in steps how to connect oracle db with sf2/3 is most appreciated.

  • link of github relies same issue that im facing https://github.com/doctrine/dbal/issues/1564

    • i have also changed the parameter.yml file

       parameters:
       database_driver: oci8
       database_user: <user>
       database_password: <password>
       database_charset: WE8MSWIN1252
       database_name: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<host>)(PORT=<port>))(CONNECT_DATA=(SERVICE_NAME=<service_name>)))
      

then error you have requested non-existence parameter "database_host"

last & final solution i tried but didn"t worked i think there bug in sf2 for oracle

    parameters:

        database_driver: oci8    
        database_host: 
        database_port: 1521
        database_name: 
        database_user: 
        database_password: 
        domain_name: 

     doctrine:
        dbal:
            default_connection:   default
            connections:
                default:
                    driver:   "%database_driver%"
                    host:     "%database_host%"
                    port:     "%database_port%"
                    dbname:   "%database_name%"
                    user:     "%database_user%"
                    password: "%database_password%"
                    charset:  UTF8
                    persistent: true
        orm:
            auto_generate_proxy_classes: "%kernel.debug%"
            auto_mapping: true
    services:
         pdo:
            class: PDO
            arguments:
                - "oci8:Server=%database_host%;Database=%database_name%"
                - "%database_user%"
                - "%database_password%"
            calls:
                - [setAttribute, [3, 2]] # \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION

         session.handler.pdo:
            class:     ESERV\MAIN\FrameworkChanges\MtlPdoSessionHandler
            arguments: ["@pdo", "%pdo.db_options%"]   
  • 写回答

1条回答 默认 最新

  • dongshou1991 2016-05-18 09:08
    关注

    here is what I use to connect MSSQL : https://github.com/realestateconz/MssqlBundle

    config.yml :

    doctrine:
    dbal:
        types:
            string: ***\BacsManagementBundle\Type\StringType
        default_connection: default
        connections:
            default: 
                host:     "%database_host%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                driver_class:   Realestate\MssqlBundle\Driver\PDODblib\Driver
                mapping_types:
                    enum: string
                    string: string
    

    hope it helps.

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型