简体   繁体   English

MySQL和Phalcon PHP中的UTF8字符问题

[英]Problems with UTF8 Characters in MySQL and Phalcon PHP

I have a project in Phalcon PHP and MySql. 我在Phalcon PHP和MySql中有一个项目。

when UTF8 characters have to keep these errors are stored. 当UTF8字符必须保存这些错误时。

For example: I save : nueva descripción ñññ in Database: nueva descipción ñññ 例如:我保存:nuevadescripciónñññinDatabase:nuevadescipciónñññ

I have tried several types of collations both in the database, tables and fields. 我在数据库,表和字段中都尝试了几种类型的排序规则。

Thanks for your help. 谢谢你的帮助。

While having properly defined database elements, you have to also set your connection to use UTF-8 ecoding. 在正确定义数据库元素的同时,还必须将连接设置为使用UTF-8 ecoding。 As of Phalcon makes use of PDO, you can try to modify your connection alike to: 从Phalcon开始使用PDO,您可以尝试修改您的连接,以便:

$di["db"] = function() {
    return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
        "host" => "localhost",
        "username" => "root",
        "password" => "1234",
        "dbname" => "test",
        "options" => array( // this is your important part
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
        )
    ));
};

Example from Phalcon Forum . Phalcon论坛的例子。

As of I'm working with Polish language, my DB collations are mostly set to utf8_polish_ci or sometimes to utf8_universal_ci . 从我使用波兰语开始,我的数据库整理主要设置为utf8_polish_ci或有时设置为utf8_universal_ci You have to test it out because of result sorting issues. 由于结果排序问题,您必须测试它。

check your project database if it is utf8-unicode-ci collation. 检查项目数据库是否为utf8-unicode-ci整理。 Also check all your individual table has collation utf-8-unicode-ci 还要检查所有单个表是否有整理utf-8-unicode-ci

If it is not ok ,check your apache mysql config my.ini file 如果不行,请检查您的apache mysql config my.ini文件

In that check UTF 8 Settings has no hash (#) comment like this 在该检查中,UTF 8设置没有这样的散列(#)注释

## UTF 8 Settings
init-connect=\'SET NAMES utf8\'      //remove #
collation_server=utf8_unicode_ci         
character_set_server=utf8

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

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