简体   繁体   English

Ho使用PEAR DB从utf8编码的PHP访问latin1编码的数据库

[英]Ho to acces a latin1-encoded database from utf8-encoded PHP using PEAR DB

I'm finding some older answers to this questions, but as I got this problem just now, I'm reposting as I assume there are different answers now. 我正在寻找一些较早的答案,但由于我刚遇到这个问题,我在重新发布帖子,因为我认为现在有不同的答案。

I have a Mysql database (MariaDB) coded in latin1. 我有一个用latin1编码的Mysql数据库(MariaDB)。 After a server upgrade, som of my php scripts stopped working. 服务器升级后,我的PHP脚本之所以停止工作。 I think at least php was updated in the process. 我认为至少在此过程中更新了php。

It appears that I'm having problems with character encoding. 看来我在字符编码方面遇到了问题。

1) I'm unable to insert string values in the database containing non-ascii characters such as æ, ø and å. 1)我无法在包含非字母字符(例如æ,ø和å)的数据库中插入字符串值。 The string values comes from the file_name of an upload file $_FILES('file') . 字符串值来自上载文件$_FILES('file')的file_name。

2) Using phpMyAdmin (version 4.6.4 - latest Debian release) trying the query SELECT * FROM files WHERE filename = '%å%' returns no results, allthough there are several records having "å" in the filename. 2)使用phpMyAdmin(版本4.6.4-最新的Debian版本)尝试查询SELECT * FROM files WHERE filename = '%å%'的查询不会返回结果,尽管有几条记录的文件名中带有“å”。 (Trying a similar query on an UTF8-encoded database uing phpMyAdmin, returns all rows!). (使用phpMyAdmin在UTF8编码的数据库上尝试类似的查询,将返回所有行!)。

There are som older claims that PEAR DB does not support UTF8, only latin1. 有些人声称PEAR DB不支持UTF8,仅支持latin1。 But this may not be true anymore. 但这可能不再正确。 I've found there is a mysql_set_charset( 'UTF8') that should do the trick, but I want to stick to PEAR DB. 我发现有一个mysql_set_charset('UTF8')应该可以解决问题,但我想坚持使用PEAR DB。

Any ideas? 有任何想法吗?

SHOW CREATE TABLE   -- perhaps the charset change in the migration?
SHOW VARIABLES LIKE 'char%'   -- controls the _client_

etc. See "Best practice" in Trouble with UTF-8 characters; 等等。请参见《 麻烦 》中的“最佳做法”( 使用UTF-8字符); what I see is not what I stored 我看到的不是我存储的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM