0

I have a php/html application over a MySql database. Database encoding is UTF-8 and so are HTML files (<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> and <meta charset="utf-8">).

The thing is, there is inconsistency, as in a list page (plain html, no forms), I can see UTF-8 characters properly (enter image description here), and also when I select values in mysql admin, but in the edit form I see wrong characters (enter image description here) inside input text fields. This happens when I update a value inside mysql admin.

And the inverse occurs, if I update a value through the form I see characters properly inside input text field, but wrong in list (html, no forms) (enter image description here).

As I read the problem may be in the files encoding, which is confusing, as, if I list with file -i (I use linux) I see a mixture of utf-8 and us-ascii files, but if I open then with sublime text 3, I can see UTF-8 on all of them, and even if i save with encoding utf-8, file -i doesn't change result.

I also read that file -i is more a guess than a real result, so I'm quite puzzled in which encoding files have, how can I change them for real. There are many files involved, templates, libraries, etc.

EDIT: To connect to database, I use Doctrine (which I ignore internal mechanisms) and also @mysql_connect, which I force with $this->charset_utf8 = true

SOLUTION

Not really a duplicate of UTF-8 all the way through, but @deceze is right, I needed to configure Doctrine connection as explained in this SO response:

$connectionOptions = array(
    'driver'   => $options['conn']['driv'],
    'user'     => $options['conn']['user'],
    'password' => $options['conn']['pass'],
    'dbname'   => $options['conn']['dbname'],
    'host'     => $options['conn']['host'],
    'charset'  => 'utf8',
    'driverOptions' => array(
    1002 => 'SET NAMES utf8'
    )
);

$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);

Thank you

Community
  • 1
  • 1
K. Weber
  • 2,643
  • 5
  • 45
  • 77
  • 1
    Sounds like you're forgetting to set the database connection encoding somewhere. – deceze Oct 13 '16 at 14:46
  • @deceze I use Doctrine (which I ignore internal mechanisms) and also `@mysql_connect`, which I force with `$this->charset_utf8 = true`. About your *duplicated* flag, there are MANY similar questions, but not with this same problem, only in input text files. I'll read your link carefully to see if I missed something. Other solutions didn't help me – K. Weber Oct 13 '16 at 14:49
  • You might also want to see [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/). FWIW, I have no idea how `$this->charset_utf8 = true` is supposed to relate to `mysql_connect`, but I'm pretty certain that's about where your problem is. – deceze Oct 13 '16 at 15:02
  • It was a Doctrine config. issue, thanks – K. Weber Oct 13 '16 at 15:05

0 Answers0