0

I'm developing a custom module where a user (actually an admin of sorts) can upload a CSV file. Based on the contents of this file, certain rows are inserted into a table.

I'm now having problems with special characters, like é. These give the following error:

SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE9initi...' for column 'remarks' at row 1

I've tried changing the collation of the table and of the specific field, but this didn't help. The only thing that did help is changing the encoding of the file. But this puts the burden of solving the problem in the hands of the (non-technical) admin. Something I don't want.

What's more, this used to work. Before this module, things were done with a (non-Drupal) php script. The difference is that the old php script used mysql_query to insert the records, whereas I am now using db_insert.

How can I make Drupal/MySql accept the special characters in ANSI?

1 Answer 1

2

Found it. I just needed to encode the values with:

$encodedval = mb_check_encoding($val, 'UTF-8') ? $val : utf8_encode($val);
2
  • If that's what you are using, and it works, please mark this answer as accepted. It will show people you are not waiting for another answer.
    – Mołot
    Commented Jul 28, 2014 at 9:45
  • Oh, OK. I was sure there were plans to lift or at least shorten these limits on less busy sites, but it seems it didn't happened yet. Thanks for caring :)
    – Mołot
    Commented Jul 29, 2014 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.