0

I have problem with conversion from latin1 to utf8
I have got 2 databases, first is in latin1 second in utf8

Example:
select * from latin1_db gives
"SPÓŁDZIELNIA PRODUCENTÓW TRZODY ODRODZENIE BOBROWNIKI WĄGROWIEC"

but when i insert to utf8 db it becomes
"SPÓ?DZIELNIA PRODUCENTÓW TRZODY ODRODZENIEBOBROWNIKI W?GROWIEC"

how to make that both string will be same

i was using

$str=utf8_encode($str);  
$str=Encoding::fixUTF8($str);  

and

iconv  

but result was not good.

Bhavik Shah
  • 2,300
  • 1
  • 17
  • 32
binar
  • 346
  • 2
  • 4
  • 18
  • See http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored and look for "question marks". Also provide the HEX as suggested. Do not use any "fix" routines; it only complicates the issue. – Rick James Jul 29 '16 at 21:08

2 Answers2

0

You have to set the database connection encoding with

SET NAMES utf-8

as an sql query. You don't provide the code with the database request, so i cannot update your code to illustrate what i mean. With PDO it should be

$pdo = new PDO(
    'mysql:host=yourdbhost;dbname=yourdbname',
    'username',
    'password',
    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
);
u-nik
  • 488
  • 4
  • 12
  • it gives "SPÓ?DZIELNIA PRODUCENTÓW TRZODY ODRODZENIE BOBROWNIKI W?GROWIEC" it doesnt change letters ł or ą – binar Jul 29 '16 at 09:28
0

Set database connection encoding to UTF-8.

Also have a look at this answer: Convert utf8-characters to iso-88591 and back in PHP.

mb_convert_encoding();

Might be useful for you.

Community
  • 1
  • 1
tyb
  • 201
  • 4
  • 13