CakePHP-如果查询中包含特殊字符,则返回空字段 [英] CakePHP - query returns empty field if it has a special character in it

查看:72
本文介绍了CakePHP-如果查询中包含特殊字符,则返回空字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我在CakePHP中是普通的查询调用-它适用于所有结果,但是当字段中包含特殊字符时,该字段将返回空。它不会中断-仍然给我其余字段-只是一个字段为空。

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.

示例:

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

这将返回表中的所有项目(包括我认为具有空名称字段的项目) )-但是当我尝试在页面上呼应名称时,它适用于除带有特殊字符(é)的每个项目。我将其更改为普通的 e,并且显示正常。

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!

推荐答案

请检查以确保您的数据库使用正确的编码(理想情况下为UTF-8),并且您已配置Cake在 config / database.php 中也使用相同的编码:

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.

这篇关于CakePHP-如果查询中包含特殊字符,则返回空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆