Reputation: 11391
I have a drupal form which saves user input into a MySQL database using the Doctrine library. The problem is that if the user input has accentuated characters, they don't look good in the DB. For example, Sempé
becomes Sempé
. This is strange to me because:
varchar(20) COLLATE utf8_swedish_ci NOT NULL,
ENGINE=InnoDB AUTO_INCREMENT=202 DEFAULT CHARSET=utf8 COLLATE=utf8_swedish_ci
<form enctype="multipart/form-data" action="/drupal/identification" method="post" id="form-identification" accept-charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
the php->mysql connection is set to utf8:
$dbParams = array("driver" => "pdo_mysql",
"host" => variable_get("dbManip_host"),
"user" => variable_get("dbManip_user"),
"password" => variable_get("dbManip_password"),
"dbname" => variable_get("dbManip_dbName"),
"charset" => "utf8");
I also tried:
default_charset = "utf8"
to php.iniutf8_encode
before saving itmb_convert_encoding
before saving itbut none of those worked.
Am I missing anything here?
UPDATE
I had a look at the headers sent by the browser to the server and found out that $_SERVER['HTTP_ACCEPT_CHARSET'] === null
Upvotes: 0
Views: 228
Reputation: 1700
Prior to submit of any other query via a given PHP MySQL link, try:
mysql_query('SET NAMES UTF8');
This statement indicates that further queries submit via the same MySQL link will be in UTF8 charset.
When you want to later retrieve the MySQL data and publish to a web page via PHP, be sure to set the charset in the HTTP header:
header('Content-type: text/html; charset=utf-8');
...and convert to HTML entities in displayed content:
echo mb_convert_encoding($mysql_col_str, 'HTML-ENTITIES', 'UTF-8');
(this final statement assumes a variable $mysql_col_str has been defined which contains the UTF8 value returned by the MySQL query)
Upvotes: 1
Reputation: 3780
You should try adding an extra parameter called charset to the configuration of the Entity Manager:
$conn = array(
'driver' => 'pdo_mysql',
'host' => 'hostname',
'user' => 'user',
'password' => 'pass',
'dbname' => 'dbname',
'charset' => 'utf8'
);
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
Upvotes: 1