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?
Your problem doesn’t come from PHP: your
"MY_CURRENCY"."SYMBOL"column is probably defined asVARCHAR2(4 byte)instead ofVARCHAR2(4 CHAR).Since an unicode character may take more than one byte, you have to use
CHARwhen you define your tables and variables. This is why you are getting an Oracle error.You should be able to modify your table:
And then insert any 4 characters into this column.