views:

807

answers:

1

Hi everybody, I'm trying out code igniter, and I came across an error message while trying to insert a new row in my Mysql database.

The text I'm trying to insert is in French, and contains some accents.

Here's 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 seems to work fine (I've inserted a few "test test" entries), but when I try to enter something with accents, for instance "Il était là", I get an error message :

A Database Error Occurred

Error Number: 1366

Incorrect string value: '\xE9tait ...' for column 'mytext' at row 1

I've looked on the code igniter forums for a fix, but all they say is to change the collation to UTF8, in mysql. I've tried that, but I keep having the same problem.

+2  A: 

Try to uft8-encode it before you insert to the database.

utf8_encode($string)
Silfverstrom