thinkphp3查詢mssql資料庫亂碼解決方案分享_PHP教程

來源:互聯網
上載者:User
thinkphp查詢mssql資料庫出現亂碼的原因是ThinkPHP預設為UTF-8,而msmsql資料庫是簡體中文版,儲存的是GB2312編碼

解決方案:

1:在ThinkPHP\Lib\Core 開啟Db.class.php,在其最後面加上
2:在Db.class.php找到function select(),在$result = $this->query($sql);後面加一條 $result=iconv2utf8($result),就OK了

複製代碼 代碼如下:
public function iconv2utf8($Result) {
$Row=array();
$key1=array_keys($Result); //取查詢結果$Result的數組的索引值
//print_r($key1);
$key2=array_keys($Result[$key1[0]]);
//取查詢結果$Result的第一個數組($key1[0])的索引值
//print_r($key2);
for($i=0;$i
for($j=0;$j //取查詢結果編碼改為UTF-8,並存入$Row,且$Row與$Result鍵與值一致
$Row[$key1[$i]][$key2[$j]]=iconv('gb2312','utf-8',$Result[$key1[$i]][$key2[$j]]);
}
}
retrun $Row;
}

http://www.bkjia.com/PHPjc/733057.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/733057.htmlTechArticlethinkphp查詢mssql資料庫出現亂碼的原因是ThinkPHP預設為UTF-8,而msmsql資料庫是簡體中文版,儲存的是GB2312編碼 解決方案: 1:在ThinkPHP\Lib\Cor...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.