Bir DB'den UTF-8 kodlanmış içeriğin ekran ile Sorunları

6 Cevap php

Stackoverflow topluluğun mensupları,

We are developing a web application using the Zend Framework, and we are facing some encoding issues that we hope you might help us solve. The situation goes something like this: There are certain tables on a MySQL database that need to be displayed as html. Because the site is designed using the Spanish language, the database contains some characters like "á" or "ñ". Our internal policy is to set all the encodings as UTF-8, including all the databases and the tables. The problem is, that when we retrieve the content from the DB, some characters are displayed as question marks.

We are out of ideas. These are all the things that we have already tried and double-checked: 1. The SQL file from which we load all the data is properly UTF-8 encoded. 2. The SQL is loaded through phpmyadmin (which is configured as UTF-8), and the resulting tables are displayed properly. 3. The netbeans environment used for coding is also set as UTF-8.

The weird thing is that all the content that is hard-coded either as php or html is displayed properly. Only the values that are extracted from the database have issues.

Herhangi bir fikir?

Çok teşekkür ederim.

6 Cevap

kullanıyorsunuz

resources.db.params.charset = "utf8" 

gibi yapılandırma dosyasında (application.ini)?

Nasıl ayıklamak için denemek mi? CLI mysqldump VEYA phpmyadmin özü?

Ben, (SELECT, ve INSERT ile DB başa çıkma) i manuel ekstre bile bir zaman benzer sorunlar vardı.

Usualy Bu komut, sorun çözüldü mysqldump --set-character-set=latin-1 --set-charset -u user -pPASSWORD databasename > databasename-latin1.sql

Ayrıca deneyin: http://www.saiweb.co.uk/mysql/converting-mysql-latin1-to-utf8

Bu doğru bir yaklaşım olup olmadığını bilmiyorum, ama veritabanından latin karakterleri yazdırırken bu düzeltmek için ben sadece farklı bir belge kodlaması kullanın:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

Ben kesinlikle UTF-8 kodlama çalışmıyor neden emin değilim. Ben de doğru cevap arıyorum.

Eğer veritabanı sorununa bir bağlantı yapmak hemen sonra bağlantı utf-8 olarak ayarlanmış olduğundan emin olun ve aşağıdaki sql

"SET NAMES 'utf8';"

Eğer kodlama kırık olsun nerede olduğunu tespit etmek gerekir her şeyden önce. Ben senin sonrası bu konuda net bir cevap bulamadım. Sen sağlamak gerekir:

  1. Tablo kodlama doğru ayarlanmış olduğundan
  2. DB Bağlantı (verilen yani kümesi adlarını 'utf8') düzgün yapılandırılmış
  3. Zend views yapılandırılmış: resources.view.encoding = "UTF-8"
  4. Apache yapılandırılmış sağ

Yukarıdaki tüm düşünürsek muhtemelen bu yardımcı olacağını, kontrol edilir. . Aşağıdaki satırı htaccess ekle:

addDefaultCharset utf-8

Bir keresinde önce aynı problem vardı ama ben bu seçenekleri kullanmadan edildi

  • Php 5.3
  • PDO

turns out that pdo had bugs in PDO::MYSQL_ATTR_INIT_COMMAND for example try :

try {
    $pdbo = new PDO("mysql:host=localhost;dbname=test", 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}catch(PDOException $e){
    echo $e->getMessage();
}

Kaynak: http://bugs.php.net/bug.php?id=47224

ipucu: mysqli onun benim için çalıştı kullanmak