iT邦幫忙

0

php pdo連接access 中文會亂碼

  • 分享至 

  • xImage

大家好:
我連mysql是正常中文字,但改用access中文就會變亂碼,想請問有甚麼方法可以解決嗎?

謝謝

https://ithelp.ithome.com.tw/upload/images/20200624/20097057gY9VKRiMxt.png

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title></title>
</head>

<body>
<div id="content">
 <?php
     try { 
$db = new PDO("odbc:driver={microsoft access driver (*.mdb)};dbq=".realpath("test.mdb").";charset=UTF-8") or die("Connect Error");  //這裡有加UTF-8
    $rs = $db->query('select * from administrator');
    print "<pre>";
    print_r($rs->fetchAll());
    print "</pre>";     
}      
    catch(PDOException $e){ 
     
     echo $e->getMessage(); 
     
     }

    ?>  
   </div>

你要確定你的mdb資料庫也是使用utf8。
從你的圖片看來,我推測你的資料庫編碼是big5。才會在轉成utf8變成那樣子。
稍微google了一下。似乎安裝Access時,就會根據系統的預設編碼設定成Access的編碼,在繁體中文Windows上是BIG5。要正常使用的話,會需要在讀取後、寫入前轉碼。
mayyola iT邦研究生 2 級 ‧ 2020-06-29 11:20:10 檢舉
兩位大大好:
要加入轉碼才可以@@
iconv("big5", "UTF-8", 字串),所以寫入應該就要相反utf8轉big5
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答