0

我将 cakephp 与 SQL Server 2012 一起使用。在我的数据库中,我声明了 nvarchar 而不是 varchar 来显示 unicode。但是当我使用

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

结果是:

    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
                )

        )

)

它不显示 unicode 字符。

4

1 回答 1

1

您应该在 app/Config/database.php 中更改数据库设置:

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

至:

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'user',
    'password' => 'password',
    'database' => 'database_name',
    'prefix' => '',
    'encoding' => 'utf8', //uncomment this line
);
于 2013-05-19T12:59:22.440 回答