0

I'm having a weird (for me) behavior in a simple webapp built in codeigniter + doctrine.

I have a local apache server and I shared hosting with the same code and both apps connect to the same database (hosted in the shared hosting)

This database has UTF-8 Unicode charset and utf8_general_ci collation.

All forms and pages have the meta charset like this.

<!DOCTYPE html>
<html lang="es" xml:lang="es">
<head>
    <meta charset="utf-8">

The thing is, in one server (let's say local) I put something like "institució", I save it and I can see it fine, but, on the other server (the remote one) I see something like "instituci�"

Then I go to the shared hosting, I fix the word to "institució" and then I see on the local server this word is displayed as "institució"

I can't use "utf8_decode" or "utf8_encode" because depending where I save this string I have to decode or encode.

I'm sure I'm missing some configuration but I don't know where to start with.

Locally I've got installed the default apache2 server of Mavericks.

I retrieve post data and save it into the doctrine object like this:

$question->setQuestion($this->input->post('question'));

I thought codeigniter and doctrine take care of this.

Thanks!

1 Answers1

0

Solved!

I should have had more patiente. The solution is to add an new option to connectionOptions array located in application/libraries/Doctrine/doctrine.php

The new option is called driverOptions and it looks like this:

        'driverOptions' => array(
            1002=>'SET NAMES utf8'
        )

So the whole connectionOptions is like this:

    // Database connection information
    $connectionOptions = array(
        'driver' => 'pdo_mysql',
        'user' => $db['default']['username'],
        'password' => $db['default']['password'],
        'host' => $db['default']['hostname'],
        'dbname' => $db['default']['database'],
        'charset' => 'utf8',
        'driverOptions' => array(
            1002=>'SET NAMES utf8'
        )
    );

This new option solved my problem of having different behaviors depending on the server.

Hope it can help someone!