Doctrine 2.1 and utf-8 tables


Can someone tell me how to get Doctrine to create UTF-8 and utf8_polish_ci ? My Doctrine config file has the following db configuration options:

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

However, it still creates a table with standard coding: latin1 and latin1_swedish_ci .

+6
source share
3 answers

You install it in your database, the doctrine uses only the default values ​​for the databases. See this question from the Doctrine 2.1 FAQ:

4.1.1. How to set encoding and sorting for MySQL tables?

You cannot set these values ​​in annotation, yml or xml files. To do work with the default database and collation, you must configure MySQL to use as the default encoding or create a database with charset and collation details. Thus, they are inherited to all newly created tables and columns of the database.

+7
source

Use the following code to set the sorting, encoding, and Doctrine engine:

 /** * @ORM\Table(name="temporary", options={"collate"="utf16_latin_ci", "charset"="utf16", "engine"="MyISAM"}) * @ORM\Entity */ 
+4
source

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

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

which will allow your created tables to inherit the encoding and match the values

+3
source

Source: https://habr.com/ru/post/902689/


All Articles