Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine: special characters are not saved into database string field

im trying to save into a string field (mysql database) with doctrine (in symfony2):

$blogpost->setTitle = "Test !§$%&/()=? äöü ÄÖÜ :D";

$em = $this->getDoctrine()->getManager();
$em->persist($blogpost);
$em->flush();

but it saves me: "Test !" (the rest is missing)

the entity is:

/**
 * @ORM\Column(type="string")
 */
protected $Title;

the mysql database is utf8_general_ci.

(when i add an entity manually with phpmyadmin it works correctly.)

i need to have the german umlauts. hope you can help me.

like image 814
bench-o Avatar asked Jan 25 '13 23:01

bench-o


2 Answers

You have to set the encoding for your entity manage connection string:

doctrine:
    dbal:
        driver: %database_driver%
        host: %database_host%
        port: %database_port%
        dbname: %database_name%
        user: %database_user%
        password: %database_password%
        charset: UTF8

This way you can have UTF8 characters on all the columns in your database.

like image 154
Reza S Avatar answered Oct 15 '22 08:10

Reza S


In this file vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php

they have

if ( ! isset($options['collate'])) {
  $options['collate'] = 'utf8_unicode_ci';
}

Try changing it to utf8_general_ci

Also have a look here

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/faq.html#how-do-i-set-the-charset-and-collation-for-mysql-tables

like image 30
Mirage Avatar answered Oct 15 '22 08:10

Mirage