We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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))
    ->execute();

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

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

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 = 好")
    ->execute();

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` = '好'")


1.3k
Accepted
answer