Problems with UTF8 characters in MySQL and Phalcon PHP

I have a project in Phalcon PHP and MySql.

when UTF8 characters should contain these errors.

For example: I save: nueva descripción ñññ in the database: nueva descipción à ± à ± à ±

I tried several types of sortings in both database, tables, and fields.

Thank you for your help.

+4
source share
2 answers

If you have correctly defined database elements, you must also establish a connection to use UTF-8 encoding. Since Phalcon uses PDO, you can try changing your connection like this:

$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'
        )
    ));
};

An example from the Phalcon Forum .

, utf8_polish_ci utf8_universal_ci. - .

+4

, utf8-unicode-ci. , utf-8-unicode-ci

, apache mysql config my.ini

UTF 8 hash (#),

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

Source: https://habr.com/ru/post/1617251/


All Articles