php - Can't get the encoding right in MySQL -
i have been struggling encoding problems in mysql while. building database contain not latin cyrillic , arabic text well. here example on how create database:
create database db1 default character set utf8 collate utf8_unicode_ci;
then table:
create table temptb1 ( id int primary key, name varchar(100) not null, arabic varchar(100) not null ) default character set utf8 collate utf8_unicode_ci;
and when put data , select strange characters. wrote small php script test doesn't work either:
<?php header('content-type: text/plain; charset=utf-8'); $a = mysql_connect('localhost','root','') or die('problem connecting database!'); $b = mysql_select_db('db1') or die('problem selecting database'); mysql_set_charset('utf8'); mysql_query("set names 'utf8'"); mysql_query('set character set utf8'); $query = mysql_query("select * tb1;"); while($row = mysql_fetch_assoc($query)) { $id = $row['id']; $name = $row['name']; $arabic = $row['arabic']; echo $id.' '.$name.' '.$arabic.php_eol; } ?>
i have tested both utf8_unicode_ci
, utf8_general_ci
. wrong? btw have easyphp 5.2.10.
whatever happens characters, happens before reach mysql, guess. characters converted numbers computer when enter characters. these numbers travel here there, between web forms , servers, web servers , scripting interpreters, database servers , web pages following same way.
where , how enter data? data should exit way entered. if data provided via web forms, check web page encodings , how submit forms. how them in php scripts , how send them database server. guilty part here not mysql place. can mysql too; not place of possible misbehavior , not.
check pages, check headers arrive browser.
about comments question received, no not use iso5 because need multiple of iso5 families. must go unicode encoding, of time, best being utf-8. also, not mysql library use unless library has known bugs unlikely old. :) should still use whatever recommended best practices; current problem not related library use. evil @ difference between how enter data , how view it.
Comments
Post a Comment