Linux系統中關於Sqlite3中文亂碼問題及解決辦法

來源:互聯網
上載者:User

標籤:

新做的一個項目在本地(Win8)測試時沒有問題,但傳到伺服器(Linux)時從Sqlite3資料庫查詢到的資料中文卻是亂碼(資料庫中是正常的)將php檔案、html檔案都設定成統一的utf8還是一樣,在網路上也找了各種解決方案都沒有任何用.解決辦法:將查詢到的資料重新處理,全部強制轉換成UTF8
//開啟db.db表$db = new SQLite3(‘db.db‘);if(!$db){   echo $db->lastErrorMsg();   exit;} else {}$keys = array();$students = array();//查詢$ret = $db->query("SELECT * from student limit 50");//將結果儲存到新數組while($row = $ret->fetchArray(SQLITE3_ASSOC) ){   $keys = array_keys($row);   //轉換列值,防止出現亂碼   foreach($keys as $key){      $row[$key] = mb_convert_encoding($row[$key],"gb2312","utf-8");   }   //添加到新數組   array_push($students, $row);}$db->close();print_r($students);

  

  參考:sqlite#pragma_encoding關於SQLITE版本和中文亂碼的小結Set PRAGMA encoding =“UTF-16” for main database in sqlite



來自為知筆記(Wiz)



Linux系統中關於Sqlite3中文亂碼問題及解決辦法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.