Codeigniter: problem with accent insertion in Mysql

I am trying to start a code igniter and I came across an error message while trying to insert a new row into my Mysql database.

The text I am trying to insert is in French and contains some accents.

Here is my code:

    $data= array(
        'title' => $this->input->post('title'),
        'date' => $this->input->post('date'),
        'mytext' => $this->input->post('mytext')
        );

    $this->db->insert('blog', $data); 

This code works fine (I inserted a few test test entries), but when I try to enter something with accents, such as "Il était là", an error message appears:

Database error occurred

Error Number: 1366

Invalid string value: '\ xE9tait ...' for column 'mytext' in row 1

I was looking for forums for igniters to fix, but all they say is change the sort to UTF8 in mysql. I tried this, but I have the same problem.

+3
1

uft8-encode ​​ .

utf8_encode($string)
+7

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


All Articles