4

I have problem with encoding characters from database. I am using Postgres with win1250 encoding, but whatever I put in core.php (right now I have this line of code):

Configure::write('App.encoding', 'iso-8859-1');

sometimes it give me some strange letters from database, for example È indstead of Č. Is there anything that I can do to get correct encoding.

NOTE: I can't edit or change anything to database.

2 Answers 2

10
+100

I think all you need to do is declaring the right encoding option in your database connection configuration, as described at http://book.cakephp.org/2.0/en/development/configuration.html#database-configuration (scroll a bit).

Look at this particular paragraph:

encoding

Indicates the character set to use when sending SQL statements to the server. This defaults to the database’s default encoding for all databases other than DB2. If you wish to use UTF-8 encoding with mysql/mysqli connections you must use ‘utf8’ without the hyphen.


I had the same issue (with French and Spanish names) in a previous project and I only had to add the following to my $default connection, in the app/Config/database.php configuration file:

'encoding' => 'utf8'

Maybe you need the utf8 connection or the iso-8859-1 you mentionned.

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

Comments

0

win1250 encoding is similar to iso-8859-2 (see http://en.wikipedia.org/wiki/Windows-1250), so you might want to try that instead of iso-8859-1.

3 Comments

When I try this characters are ok, but I get this error: Warning: htmlspecialchars() [php.net/function.htmlspecialchars]: charset ` iso-8859-2' not supported, assuming iso-8859-1 in /..../lib/Cake/basics.php on line 192
You might want to try to convert to cp1252 instead of iso-8859-2, as this is encoding is supported by htmlspecialchars (see be2.php.net/manual/en/function.htmlspecialchars.php). I however do not know how well win1250 maps to cp1252.
Nothing happen. Still have some issue. Is there any function that can help me to somehow convert encoding when want to read/write data to database.

Your Answer

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