简体   繁体   中英

encoding issue in sybase to php

First of all let me say ,i have a sybase database its charset is definitely not utf-8.and i cant change it to utf-8 because of some other issues.

so the problem is i need to read a data from this datbase with php and save it to a mysql table which is utf8.

so normally with out any conversion the value is saved in my database as

//sybase query
$result= someFuntionToReturnSybaseData();
//the $result is a multidimensional array
echo $result[0]['somevalue']; //19’’ long bla bla

if i try to insert this into mysql table with default charset,the value is saved as "19?? long bla bla"

in the browser it is showing as "19Â'Â' long bla bla"

is there anyway to save "19'' long bla bla" in mysql table as it is and show it correctly every where

i tried

utf8_encode($result[0]['somevalue']);
iconv();

but more garbled characters are appearing

please dont tell me to use a charset everywhere the same as i cant do that

Sybase charset iso_1 appears to be iso-8859-1 for MySQL ( https://www.connectionstrings.com/ase-unsupported-charset/ )

You can use the mysl command SET NAMES to specify the character you send to MySQL, before importing the data

SET NAMES 'iso-8859-1';

http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html

First of all, you need to get your data from sybase and convert it to UTF-8 so you can upload it to MySQL:

$resultInISO = someFuntionToReturnSybaseData();//ISO-8859-1
$resultInUTF8 = mb_convert_encoding($resultInISO,"UTF-8","ISO-8859-1");
//now it's in UTF8, you can insert it into MySQL

http://php.net/manual/en/function.mb-convert-encoding.php

Let me know if this works for you.

Quick solution is here:

Detect encoding and make everything UTF-8

and source code you need according to that article is here:

https://github.com/neitanod/forceutf8

But if you need something simpler than we need to discuss the full path from db to your code line data passed.

could you show someFuntionToReturnSybaseData() source code?

can we change that function? or you just call it as is?

what is the original codepage of db?

do you have other webpages that works fine with this sybase db?

what code page setting for those pages?

what is your mysql db table structure?

could you show CREATE TABLE statement for mysql?

and your code where you try to insert data?

and the very last question, but really not the one you should ignore:

what is your php file code page?

(I have expirience developing Cyrillic websites, and had a lot of situations when the original .php file code page had hurt the result outputs :-) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM