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
.
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.
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
*/
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With