Welcome Guest, Not a member yet? Register   Sign In
need help on unicode
#1

[eluser]daydreamer[/eluser]
I am new to php and ci. I am confused with handling unicode and hope someone could point me to the right direction.

I need to migrate a website (pure procedural php+mysqli) to ci+MCV.

My problem is when I get a varchar (utf8_unicode_ci) field from mysql, the result on the old website displayed is correct:
Être dans les choux
But on CI, the result displayed is:
Être dans les choux


When I use mb_detect_encoding on the results, both are UTF-8.

Here are my CI config/database setting:
$config['charset'] = "UTF-8";
$db['default']['dbdriver'] = "mysqli";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_unicode_ci";
And php files are saved as utf8 format

Any hints to troubleshoot this? Thanks.

Simple test page: test

Source of ci site:
controller and model:
Code:
class Test extends Controller {
    function index()      
    {
        $this->load->model('Test_model');
        $data['event_list'] = $this->Test_model->get_event_name();
        $this->load->view('test', $data);            
    }
}

class Test_model extends Model {
    function Test_model()
    {
        parent::Model();
        $this->load->database();
    }
  
    function get_event_name()
    {
        $query = $this->db->query('SELECT eventname FROM event WHERE eventId=7663');
        $row = $query->result_array();
        $query->free_result();
        return $row;
    }
}
view:
Code:
<?=$event_list[0]['eventname'].' (mb_detect_encoding: '.mb_detect_encoding($event_list[0]['eventname']).')';?>

Source of old site :
Code:
$sql  = "SELECT eventname FROM event WHERE eventId=7663";
$mysqli = new mysqli(dbHost, dbLoginName, dbPassword, dbName);  
$row    = $mysqli->query($sql)->fetch_assoc();
echo $row['eventname'].' (mb_detect_encoding: '.mb_detect_encoding($row['eventname']).')';
$mysqli->close();
#2

[eluser]Atharva[/eluser]
There is one setting in system/application/config/config.php file
Code:
$config['charset'] = "UTF-8";

Make sure it is still there.
#3

[eluser]daydreamer[/eluser]
Yes, the setting is there. Thank Atharva.
#4

[eluser]selinan[/eluser]
normally, set the unicode as your target language code, such as, english site use: UTF-8 is okay!
#5

[eluser]daydreamer[/eluser]
I already put <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> in the view, the result through ci model is not the same as from php>mysqli directly. Thanks selinan.
#6

[eluser]InsiteFX[/eluser]
Go into PhpMyAdmin click on your database name.
Go and click on the operations tab.
Check on the very bottom and see what your database collation
is set to.

When you create a new database with PhpMyAdmin it defaults to
latin1_swedish_ci you need to change it to utf8_unicode_ci

InsiteFX
#7

[eluser]daydreamer[/eluser]
The database and all tables are already utf8_unicode_ci. Btw, I use CI version 1.7.3, would it be better to use version 2?
Thanks InsiteFX.
#8

[eluser]Cristian Gilè[/eluser]
Yes, CI2 provides unicode support for UTF-8 environments.

Cristian Gilè
#9

[eluser]InsiteFX[/eluser]
But did you do what I said above?

InsiteFX
#10

[eluser]daydreamer[/eluser]
[quote author="InsiteFX" date="1294541013"]But did you do what I said above?

InsiteFX[/quote]

The database, table and the field are utf8_unicode_ci, I didn't change it since I pick up the project.




Theme © iAndrew 2016 - Forum software by © MyBB