Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2.1 and tables utf-8 coding


Could someone tell me how to force Doctrine to create database tables with UTF-8 coding and utf8_polish_ci? My Doctrine config file has this db configuration parameters:

$conn = array(
    'driver' => 'pdo_mysql',
    'dbname' => 'test',
    'user' => 'root',
    'password' => '*****',
    'charset' => 'utf8',
    'driverOptions' => array(1002=>'SET NAMES utf8'));

Nevertheless, it's still creating table with default coding: latin1 and latin1_swedish_ci.

like image 620
Jazi Avatar asked Nov 29 '11 19:11

Jazi


3 Answers

You set it in your database, doctrine just uses the databases default values. See this question from the Doctrine 2.1 FAQ:

4.1.1. How do I set the charset and collation for MySQL tables?

You can’t set these values inside the annotations, yml or xml mapping files. To make a database work with the default charset and collation you should configure MySQL to use it as default charset, or create the database with charset and collation details. This way they get inherited to all newly created database tables and columns.

like image 106
hakre Avatar answered Nov 14 '22 04:11

hakre


Use code below to set Doctrine collation, charset and engine:

/**
* @ORM\Table(name="temporary", options={"collate"="utf16_latin_ci", "charset"="utf16", "engine"="MyISAM"})  
* @ORM\Entity
*/
like image 43
Igor Vizma Avatar answered Nov 14 '22 04:11

Igor Vizma


When you create your database, you should create it like this:

CREATE DATABASE `your_table_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_polish_ci;

that will allow your created tables to inherit the charset and collate values

like image 40
chriswoodford Avatar answered Nov 14 '22 05:11

chriswoodford