gpt4 book ai didi

php - 无法使用 symfony2 连接数据库 oracle

转载 作者:行者123 更新时间:2023-12-01 14:12:59 25 4
gpt4 key购买 nike

我需要什么

  • 我需要用 symfony2 连接 oracle 数据库。

  • 我已经通过 php -m 检查过了

    • oci8
    • pdo_odbc

    • 数据库

这是我关注的链接https://gist.github.com/johnkary/6481664

a.)config.yml

学说配置

 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.) 参数.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 }
  • 然后运行 ​​symfony 数据库 cmd

     php bin/console doctrine:database:create

错误:

 cannot create database test for connection named default.
notice: undefined index dbname
  • 我用谷歌搜索了一天,但我认为很少有开发人员使用 symfony2 和 oracle。

  • 我制作了简单的 php 脚本来测试连接

    $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);

输出

       Resource id #3

tsnames.ora

    test=

(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = sss)(PORT = 1521))
(CONNECT_DATA = (SID = test))
)
  • 我用过 sf3 和 mysql,但我是 oracle 的新手,所以我不知道如何将 oracle 数据库与 symfony 连接。

  • 如果我做错了,请给出一些解决方案。

  • 谁能在步骤中建议如何将 oracle db 与 sf2/3 连接,非常感谢。

  • github 的链接依赖于我面临的相同问题 https://github.com/doctrine/dbal/issues/1564

    • 我也修改了parameter.yml文件

       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>)))

然后错误你请求了不存在的参数“database_host”

我尝试过但没有成功的最后一个解决方案我认为 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%"]

最佳答案

这是我用来连接 MSSQL 的内容:https://github.com/realestateconz/MssqlBundle

配置文件:

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

希望对您有所帮助。

关于php - 无法使用 symfony2 连接数据库 oracle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37024817/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com