CodeIgniter Forums
Database charset problems - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Database charset problems (/thread-6049.html)



Database charset problems - El Forum - 02-13-2008

[eluser]Armorfist[/eluser]
I'm trying to make an insert with Active Record ($this->db->insert) and I'm getting the following error (MySQL database):


Incorrect string value: '\xF3' for column 'address' at row 1

INSERT INTO `login_userdata` (`email`, `name`, `last_name`, `address`, `location`, `postal_code`, `phone`, `birth_date`, `sex`, `user_id`) VALUES ('email@test.com', 'Name', 'LastName', 'Cósta de Cáparica', 'Cósta de Cáparica', '2825-351', '2112121212', '28/02/89', '0', 12)


The string that corresponds to the "address" column is "Cósta de Cáparica".

I have the "<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />" tag in the html where form is, $config['charset'] = "UTF-8";, and the column where this data is inserted is collation "utf8_general_ci".

Anyone has any idea whats going on?

Thanks.


Database charset problems - El Forum - 02-13-2008

[eluser]Derek Allard[/eluser]
What's the datatype of the address field?


Database charset problems - El Forum - 02-13-2008

[eluser]Armorfist[/eluser]
The datatype of all fields except "user_id", "sex" and "birthdate" is varchar(255). I cannot add that string (Cósta de Cáparica) to any of them.

SQL of the table:
Code:
CREATE TABLE `login_userdata` (
  `user_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `last_name` varchar(255) NOT NULL,
  `address` varchar(255) NOT NULL,
  `location` varchar(255) NOT NULL,
  `postal_code` varchar(255) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `birth_date` date NOT NULL,
  `sex` int(11) NOT NULL,
  `notes` varchar(80) default NULL,
  PRIMARY KEY  (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

I can insert normally if i do not use "special" chars like "ó".

Thanks,


Database charset problems - El Forum - 02-13-2008

[eluser]Derek Allard[/eluser]
Hm, then I'm not sure what's going on for you. I've just tested this on 2 setups, and things for for me very nicely - I have not problem inserting that string. Sorry Armorfist, not sure what might be the problem. Do you have another server you could test on?


Database charset problems - El Forum - 02-13-2008

[eluser]Armorfist[/eluser]
Yes i do, i will try it and give my feedback asap.
Thanks.


Database charset problems - El Forum - 02-13-2008

[eluser]Armorfist[/eluser]
Just tested it in my production server and its all working fine.
The production server is running Linux and the development server is running Windows. The versions of php and mysql are the same in both servers. I have no idea what could be the problem, but i will continue testing. If you think of something please tell me.

Thanks for all your help!


Database charset problems - El Forum - 02-13-2008

[eluser]Derek Allard[/eluser]
No problem. I just fired up a test installation on a windows box and it also worked fine. Truthfully, I can't think of what it might be... sorry. Do let us know if you come up with anything!


Database charset problems - El Forum - 02-13-2008

[eluser]Armorfist[/eluser]
I just changed the "default_charset" setting in the php.ini file to "" (empty) and it worked. Now it gets the character encoding from the "Content-type" header.

Thanks again for all your help, great work on CI.

Regards