简体   繁体   中英

Problems with UTF8 Characters in MySQL and Phalcon PHP

I have a project in Phalcon PHP and MySql.

when UTF8 characters have to keep these errors are stored.

For example: I save : nueva descripción ñññ in Database: nueva descipció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. As of Phalcon makes use of PDO, you can try to modify your connection alike to:

$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 .

As of I'm working with Polish language, my DB collations are mostly set to utf8_polish_ci or sometimes to 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. Also check all your individual table has collation utf-8-unicode-ci

If it is not ok ,check your apache mysql config my.ini file

In that check UTF 8 Settings has no hash (#) comment like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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