tags:

views:

3278

answers:

1

I'm having a little problem with a php-gtk app that keeps running into non-utf8 strings, I had found that the problem is in the database connection, even when the database is supposed to be in UTF-8.

I had tried with the "SET CHARACTER SET utf8"(MySQL way) and the "SET NAMES UTF8" and nothing happen (there isn't any information about none of this commands in the "Query Language Understood by SQLite " page either, so I'm not surprised about that).

PD: Maybe the connection is already in UTF-8 and the data isn't, but if there is a way to change the connection encoding this question would still be useful.

+2  A: 

As far as I can tell, SQLite only has one setting for charset, which is on a per-database level. You can't change the encoding on the connection.

The C API has two different ways of opening a connection, either as UTF-8 or UTF-16. I would expect PHP's SQLite module (And thus PDO) to simply use the UTF-8 version. If that's correct, I would expect that a SQLite connection is always UTF-8. This means that you ought to manually encode/decode strings with utf8_encode/utf8_decode.

Also see: http://www.alberton.info/dbms_charset_settings_explained.html

troelskn
I had Discovered that "SQLite is not particular about the text it receives and is more than happy to process text strings that are not normalized or even well-formed UTF-8. programmers who want to store IS08859 data can do..." Soo the text was originilally in ISO85(something)
levhita
I followed your advice and added a couple of utf8_encodes (thank you programming gods for OOP) so everything is utf8 from the start.My main database has been recreated in UTF8, and I just added those line to couple my system with some plugin databases.
levhita
In that case, you'll have to use utf8_decode when retrieving data back. This is all only needed, if you use PHP's default charset (ISO-8859-1) internally. Consider using UTF-8 all through your system, in which case you don't have to encode anything (Yes, it's confusing).
troelskn