Doctrine: special characters not stored in database string field

im trying to save in a row field (mysql database) using 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)

an object:

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

      

mysql database - utf8_general_ci.

(when I add the object manually using phpmyadmin it works correctly.)

I need to have German umlauts. hope you can help me.

+3


source to share


2 answers


You have to set the encoding for your entity to control the 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 in all columns of your database.

+3


source


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

+2


source







All Articles