Search code examples
cakephpfindspecial-characterscakephp-2.1

cakephp find returns empty array for spanish characters


I am using the latest CakePHP (2.1.x) and when I do a find like the following, it returns an empty array when the Model.name field contains a Spanish character:

$this->Model->find(
        'list', 
        array(
            'conditions' => array(
                'LOWER(Model.name) LIKE' => '%'.$keyword.'%'
            ),
            'fields' => array(
                'Model.id', 
                'Model.name'
            )
        )
    );

When I display the sql_dump element, the query is just fine and it says 0 Error, 1 Affected and 1 Num Rows; plus when I try the query it's working just fine on the phpMyAdmin as well.

The whole website is in English and the content type is UTF-8. I tried to change the encoding without success.

The field is stored on the DB (MySQL) as name varchar(255) latin1_swedish_ci if this could be of any help.


Solution

  • Maybe you need to specify the utf-8 encoding on the database connection too

    Check this out, hope it helps