0

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

coolguy
  • 7,866
  • 9
  • 45
  • 71
  • Do you know what charset sybase is using? – deceze Feb 20 '15 at 06:42
  • @deceze can you help me out man ? – coolguy Feb 20 '15 at 11:17
  • 1
    you may need to use this function `mb_convert_encoding`. For more details you may want to check http://php.net/manual/en/function.mb-convert-encoding.php (and the comments on that page as well) – xycf7 Feb 23 '15 at 15:25
  • How much data is involved? If you can dump the data to a CSV (or similar) file, plus do a hex dump of a little of the naughty characters, I may be able to walk you through converting it via MySQL. – Rick James Feb 23 '15 at 22:40
  • im able to encode to utf8 using notepad++ 's convert to utf8 functionality.but i need it on the fly..some function inline – coolguy Feb 24 '15 at 03:34
  • could you show `someFuntionToReturnSybaseData()` source code? can we change that function? or you just call it as is? – Alex Feb 25 '15 at 14:26
  • and what is your mysql db table structure? could you show `CREATE TABLE` statement for mysql? and your code where you try to insert data? – Alex Feb 25 '15 at 14:42

3 Answers3

1

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

Adam
  • 17,838
  • 32
  • 54
1

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.

Paweł Tomkiel
  • 1,974
  • 2
  • 21
  • 39
1

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 :-) )

Community
  • 1
  • 1
Alex
  • 16,739
  • 1
  • 28
  • 51