duanhuo0577 2013-05-19 04:41
浏览 21

如何在使用SQL Server时显示cakephp中的unicode

I use the cakephp with SQL server 2012. In my database I have declare nvarchar instead of varchar to show the unicode. But when I use

$this->set('types',$this->Manager->query('select * from product_types'))

the result is :

    Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [id] => 2
                    [name] => Th?c u?ng c� c?n
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [id] => 3
                    [name] => B�nh k?o
                )

        )

    [2] => Array
        (
            [0] => Array
                (
                    [id] => 4
                    [name] => X� b�ng
                )

        )

    [3] => Array
        (
            [0] => Array
                (
                    [id] => 5
                    [name] => H�ng h�a d�ng h?p
                )

        )

)

It doesn't show unicode characters.

  • 写回答

1条回答 默认 最新

  • dongyan6235 2013-05-19 12:59
    关注

    You should change your database setting in app/Config/database.php:

    public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'user',
        'password' => 'password',
        'database' => 'database_name',
        'prefix' => '',
        //'encoding' => 'utf8',
    );
    

    to:

    public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'user',
        'password' => 'password',
        'database' => 'database_name',
        'prefix' => '',
        'encoding' => 'utf8', //uncomment this line
    );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理