Symfony2+Doctrine: How to convert iso8859-1 to utf-8 and viceversa?

后端 未结 2 2080
南笙
南笙 2021-01-20 21:40

We\'re building a Symfony2 app that\'s using an Oracle database. All the data in the DB is encoded as WE8ISO8859P15 (iso-8859-1), and all the website is encoded as utf-8.

2条回答
  •  萌比男神i
    2021-01-20 21:45

    I solve a similar problem with a MSSQL instance for convert from utf8 to latin1 and viceversa. I do the following step:

    1. Define a custom DBAL Type
    2. Initialise on the boot Bundle method (i think you can do in the config.yml too)
    3. Use it as annotation on the entity field

    This his the code:

    DBAL CUSTOM TYPE

    BUNDLE INITIALISATION

    container->get('doctrine.orm.em_my_sqlserver_entity_manager');
                $conn = $em->getConnection();
                $conn->getDatabasePlatform()->registerDoctrineTypeMapping('Utf8String', 'utf8string');
            }
        }
    
    }
    

    AN EXAMPLE MAPPED ENTITY

    Hope this help and hoping you find a better solutions too!!!

提交回复
热议问题