oracle数据库symfony,使用Doctrine2和Symfony2将unicode数据插入Oracle数据库(Inserting unicode data into Oracle Databa...

使用Doctrine2和Symfony2将unicode数据插入Oracle数据库(Inserting unicode data into Oracle Database with Doctrine2 and Symfony2)

我正在使用Symfony2和Doctrine2编写应用程序,我需要使用Oracle作为我的数据库(我不熟悉,我几乎总是使用MySQL)。 我在开发箱上安装了Oracle XE并创建了一个用户。

我的Symfony2配置中的连接参数如下所示:

database_driver: oci8

database_host: localhost

database_name: xe

database_user: myusername

database_password: mypassword

database_port: 1521

database_charset: AL32UTF8

当运行php app/console doctrine:schema:create在CLI上php app/console doctrine:schema:create时,架构已成功创建,但在尝试使用php app/console doctrine:fixtures:load加载我的初始灯具时,我收到以下错误:

[Doctrine\DBAL\DBALException]

An exception occurred while executing 'INSERT INTO my_currency

(id, code, name, symbol) VALUES (?, ?, ?, ?)' with params

{"1":3,"2":"RUB","3":"Russian Ruble","4":"\u0440\u0443\u0431."}:

ORA-12899: value too large for column "MYUSERNAME"."MY_CURRENCY"."SYMBOL"

(actual: 7, maximum: 4)

我的fixtures脚本中包含以下数据用于插入此行:

array('RUB', 'Russian Ruble', 'руб.'),

该实体定义为:

Foo\MyBundle\Entity\Currency:

type: entity

table: my_currency

id:

id:

type: integer

generator: { strategy: AUTO }

fields:

code:

type: string

length: 3

name:

type: string

length: 64

symbol:

type: string

length: 4

据我所知,Oracle XE的默认字符集为UTF-8,因此字段类型不需要设置为NVARCHAR2(它们由Doctrine自动设置为VARCHAR2)。

有没有人对我出错的地方有任何想法?

I'm writing an application using Symfony2 and Doctrine2 where I need to use Oracle as my database (of which I am unfamiliar with, I almost always use MySQL). I have installed Oracle XE on my dev box and created a user.

My connection parameters look like this in my Symfony2 config:

database_driver: oci8

database_host: localhost

database_name: xe

database_user: myusername

database_password: mypassword

database_port: 1521

database_charset: AL32UTF8

When running php app/console doctrine:schema:create on the CLI, the schema is created successfully, but when trying to load my initial fixtures with php app/console doctrine:fixtures:load, I'm getting the following error:

[Doctrine\DBAL\DBALException]

An exception occurred while executing 'INSERT INTO my_currency

(id, code, name, symbol) VALUES (?, ?, ?, ?)' with params

{"1":3,"2":"RUB","3":"Russian Ruble","4":"\u0440\u0443\u0431."}:

ORA-12899: value too large for column "MYUSERNAME"."MY_CURRENCY"."SYMBOL"

(actual: 7, maximum: 4)

My fixtures script has the following data in it for inserting this row:

array('RUB', 'Russian Ruble', 'руб.'),

The entity is defined as:

Foo\MyBundle\Entity\Currency:

type: entity

table: my_currency

id:

id:

type: integer

generator: { strategy: AUTO }

fields:

code:

type: string

length: 3

name:

type: string

length: 64

symbol:

type: string

length: 4

From what I understand, Oracle XE has a default character set of UTF-8, so the field types shouldn't need to be set to NVARCHAR2 (they're set to VARCHAR2, automatically by Doctrine).

Does anyone have any ideas as to where I'm going wrong?

原文:https://stackoverflow.com/questions/13359606

更新时间:2020-07-10 12:07

最满意答案

您的问题不是来自PHP:您的"MY_CURRENCY"."SYMBOL"列可能定义为VARCHAR2(4 byte)而不是VARCHAR2(4 CHAR) 。

由于unicode字符可能需要多个字节,因此在定义表和变量时必须使用CHAR 。 这就是您收到Oracle错误的原因。

你应该能够修改你的表:

ALTER TABLE MY_CURRENCY MODIFY (SYMBOL VARCHAR2(4 CHAR));

然后在此列中插入任意4个字符。

Your problem doesn't come from PHP: your "MY_CURRENCY"."SYMBOL" column is probably defined as VARCHAR2(4 byte) instead of VARCHAR2(4 CHAR).

Since an unicode character may take more than one byte, you have to use CHAR when you define your tables and variables. This is why you are getting an Oracle error.

You should be able to modify your table:

ALTER TABLE MY_CURRENCY MODIFY (SYMBOL VARCHAR2(4 CHAR));

And then insert any 4 characters into this column.

2012-11-13

相关问答

好的,我知道了。 只需使用QueryBuilder。 $arr_products = $pack_repo->createQueryBuilder('p')

->where('p.active = true')

->orderBy('p.rating', 'DESC')

->getQuery()

->getResult();

Ok, got it. Just use QueryBuilder. $arr_products = $pack_repo->createQ

...

刚刚意识到我是一个完全白痴,我的问题是我的实体中状态被设置为布尔字段,因此它正在更新,但始终将其设置为1! Just realised that I've been a complete idiot and my issue is that status is set as a boolean field in my entity, so it was updating, but always setting it as 1!

我看到你正在使用: @ORM\OrderBy({"dateCreated" = "DESC"})

可能很傻,但检查返回的Check实例的ID。 Well I finally found my problem and my post here was really silly and completely unrelated to Symfony or Doctrine, sorry about that. I was performing some "tests" on the last ins

...

不幸的是,Doctrine 2.0不支持主键作为外键...查看链接: http : //www.doctrine-project.org/docs/orm/2.0/en/reference/limitations-and-known-issues.html Unfortunately Doctrine 2.0 does not support primary keys as foreign keys... Check the link: http://www.doctrine-project.or

...

不确定的目的:enumAddressSource:string 不应该枚举:字符串(如前面的行)就足够了? 你得到的错误信息基本上是告诉你没有类型称为“enumAdressSource”,因此没有这种类型可以映射到字符串。 您是映射类型,而不是此处的字段。 The causes of the error were comments nested in the columns of the MySQL database. I never would have guessed that Doctrin

...

是否可以放置一个绝对没有与数据库链接的功能? 是的,没关系。 但仔细观察,它仍然在某种程度上与数据库“链接”,因为它利用了最初来自持久层(数据库)的性别和名称数据。 这不是一个坏习惯吗? 这根本不是不好的做法,事实上它是非常有用的。 它可以帮助您在模型对象中使用持久层,同时将代码与数据库访问分离。 Is it OK to put a function which has absolutely no link with the database? Yes that's okay. But look

...

好吧,事实证明,解决方案是将连接字符串直接放入dbname: database_host: false并将host参数设置为false: database_name: '(DESCRIPTION=…' Well, as it turns out, the solution was to put the connection string into the dbname directly : database_host: false and the host parameter to false :

...

如果你仍然想用最新版本的doctrine/dbal做到这doctrine/dbal ,你所要做的就是在dbal配置中指定server_version : doctrine:

dbal:

default_connection: default

connections:

default:

dbname: local_api

user: ro

...

你必须使用$conn->insert('table', $dataArray); 。 见文档 You have to use $conn->insert('table', $dataArray);. See documentation

您的问题不是来自PHP:您的"MY_CURRENCY"."SYMBOL"列可能定义为VARCHAR2(4 byte)而不是VARCHAR2(4 CHAR) 。 由于unicode字符可能需要多个字节,因此在定义表和变量时必须使用CHAR 。 这就是您收到Oracle错误的原因。 你应该能够修改你的表: ALTER TABLE MY_CURRENCY MODIFY (SYMBOL VARCHAR2(4 CHAR));

然后在此列中插入任意4个字符。 Your problem doesn't com

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值