We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Query Using Chinese Characters Returns No Results

Target table has two columns: one column of unique Chinese characters, the other column is unique int acting as the primary key. I'm trying to return the key corresponding to a given character.

Returns 0 results:

$value = "好";
$character_id = self::query()
    ->where("character = :character:")
    ->bind(array("character" => $value))

Returns 0 results (using single quotes around the character):

$character_id = self::query()
    ->where("character = '好'")

Returns error (using no quotes around the character): Scanning error before '��' when parsing: SELECT [Characters].* FROM [Characters] WHERE character = 好

$character_id = self::query()
    ->where("character = 好")

If I query against the primary key column using an existing key it returns results, so I'm thinking this is an encoding issue. Has anyone else run into this problem?

I've tried running the query directly using sql. I've discovered "character" is a keyword in mysql, so by adding backticks around the column name, and quotes around the character itself, mysql will return results. However, I do not know how to implement this in phalcon, as the following code still produces an error: PhalconException: Scanning error before 'character = '�...' when parsing: SELECT [Characters].* FROM [Characters] WHERE character = '好' (65)

->where("`character` = '好'")