How to change character encoding of a PDO/SQLite connection in PHP?

前端 未结 1 1929
忘了有多久
忘了有多久 2020-12-11 03:16

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

相关标签:
1条回答
  • 2020-12-11 03:42

    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

    0 讨论(0)
提交回复
热议问题