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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用