0

The scenario: An html-document that's used for editing product details is encoded as ISO-8859-1, and sends POST data to a PHP-file (also encoded ISO-8859-1). That PHP-file in turn has mysql_real_escape_string -functions cleaning the inputs. The database/mysql server charset is UTF-8. The problem is that when a POST string has scandinavian letters (ä,ö,å) in it, the mysql_real_escape_string returns an empty string.

I tried to override it with utf8_encode/decode, but it won't work.

Now, if I change the html&php-files to use UTF-8, saving works fine (as expected), but then all previously saved product data looks corrupt, and there are thousands of product rows.

What would be the easiest solution to fix it? Change the db charset? Run a encoding function to convert the entries in the db?

3
  • "is encoded as ISO-8859-1" — Why? It isn't the 1990s any more. Commented Jun 13, 2013 at 12:31
  • Please note that the mysql_xxx() functions are deprecated. I recommend switching your code to use the newer PDO or mysqli libraries. Commented Jun 13, 2013 at 12:49
  • The codebase is actually from the 90's. Loving it. Commented Jun 13, 2013 at 17:57

1 Answer 1

1

mysql_real_escape_string considers the current connection character set. Your ISO-8859-1 scripts should work if you set your connection explicitly to UTF-8 before calling mysql_real_escape_string (query "SET NAMES 'utf8'" before using mysql_real_escape_string)

But for sure I would always recommend to use unicode (and only unicode) wherever it is possible;)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.