Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP - query returns empty field if it has a special character in it

I have what I think to be a normal query-call in CakePHP - it works for all results, but when a field has a special character in it, the field will return empty. It doesn't break - and it still gives me the rest of the fields - it's just that one field that's empty.

Example:

$this->paginate = array(
'conditions' => array(
     'Item.name != ' => '',
),
);
$data = $this->paginate('Item');

This will return all the items in my table (including the one that I thought had an empty name field) - but when I try to echo the name to the page, it works for every item except the one with a special character (é). I changed it to a normal "e" and it shows up fine.

How can I return results even if they have a special character in their name? Thanks in advance!

like image 939
Dave Avatar asked Apr 10 '11 06:04

Dave


1 Answers

Check to make sure your database uses the right encoding (UTF-8, ideally) and you have configured Cake to use this same encoding as well in config/database.php:

class DATABASE_CONFIG {
    public $default = array(
        ...
        'encoding' => 'utf8'
    );
}

If you have some encoding mismatch, your app has probably stored garbage in the database already, so make sure you test with the right data and/or a fresh database.

like image 193
deceze Avatar answered Oct 01 '22 20:10

deceze