2013-05-19 18 views
0

我使用cakephp和SQL server 2012.在我的數據庫中,我聲明瞭nvarchar而不是varchar來顯示unicode。但是當我使用如何在使用SQL服務器時在cakephp中顯示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字符。

+0

是字符OK,直接在數據庫? – Amir

+0

這是好的,當我使用SQL管理工作室2012查詢! –

+0

你有元標籤,如''? – Amir

回答

1

你應該改變你的數據庫設置在app /配置/ 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 
); 
相關問題