I am attempting to run a sql query but get the following error:
Incorrect string value: '\xCC_a' for column
CSV File line that breaks mysql query:
Juan Gordon,GarcÃ_a,noman@gmail.com,,,,,,,,,,y,
SQL Error:
<p>Error Number: 1366</p><p>Incorrect string value: '\xCC_a' for column 'last_name' at row 1</p><p>INSERT INTO `phppos_people` (`first_name`, `last_name`, `email`, `phone_number`, `address_1`, `address_2`, `city`, `state`, `zip`, `country`, `comments`) VALUES ('Juan Gordon', 'Garc�_a', 'noman@test.com', '', '', '', '', '', '', '', '')</p><p>Filename: /Library/WebServer/Documents/phppos/PHP-Point-Of-Sale/models/person.php</p><p>Line Number: 75</p> </div>
last_name is varchar(255) utf8_unicode_ci
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_unicode_ci';
Example CSV code
?>
last_name = GarcÌ_a
UPDATE: I just learned that when saving the file as a .csv in excel the encoding is: Westren (Mac OS Roman) with CR as line breaks.
I think that file encoding might cause the problem. But I need to support it.
The only Excel that exports to Mac OS Roman apparently is MS Excel for OSX. Unfortunately I don’t have this so I can’t check how to export with the correct character set
You now have two choices
a) Convert the CSV to UTF-8 using iconv for example
b) Set the connection charset to the character set of the file before you import
In codeigniter this would look like this
After your import is done, don’t forget to set it back
Explanation:
If your connection charset is UTF-8, your database excepts UTF-8 encoded data. If you set the connection charset to
macromanand the columns you write to are UTF-8, MySQL will automatically convert this for you.On my freeBSD machine, MySQL has the macroman character set compiled in, I suppose you’ll also have this.
Also see http://dev.mysql.com/doc/refman/5.5/en/charset-charsets.html
Hope this helps