donglun4682 2011-04-10 06:18
浏览 36
已采纳

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.

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!

  • 写回答

2条回答 默认 最新

  • doufu5747 2011-06-24 06:07
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化