Getting Arabic characters as ??? in PHP from JDE

896 Views Asked by At

I am trying to fetch our Arabic values from JDE Database using the following connection string:

$dsn = "Driver={SQL Server};Server=10.10.10.27;Database=JDE;charset=utf8";
$username = "username"; 
$password = "password";
$string = "odbc:".$dsn.";Uid=".$username.";Pwd=".$password.";";
$con = new PDO($string);

As you can see I have the charset=utf8 specified.

I also have my HTML meta present:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

I also have used arabic characters fetched from MySQL before and it is displayed correctly and I can see Arabic characters, but from JDE database I get the following:

name: ??? ???? ???? ??? ??? ??? ???? ???? ??? ???

I tried adding the following in my php code trying different output:

echo iconv('windows-1256', 'utf-8', $DataFromJDE); 
echo utf8_decode($DataFromJDE);
echo utf8_encode($DataFromJDE);

But all failed.

Is there a configuration I need to do on the server?

I am using Apache with PHP 7 on a Windows server.

The JDE is in a separate server.

What am I missing? Is it from PHP or JDE?

2

There are 2 best solutions below

10
Top-Master On

Try something like:

echo $DataFromJDE . '<br>';

Note that you don't need to use utf8_decode(...) or anything similar, browsers support UTF-8 as is, without any need for reformatting.

0
Sadeem M.K. On

YES! Finally Cracked the code! Thank you So much for the amazing explanations and clarifications. your answers helped a lot.

So basically what I had to do is.

  1. Change my query to the following

    $con->prepare('SELECT CAST( CAST(JDEColumn AS VARBINARY(MAX)) AS varchar(120)) AS JDEColumn FROM TABLE where COLUMN = :SELECTION');

courtesy of this thread here https://stackoverflow.com/a/29975739/11835221

  1. Using iconv() as follows:

    iconv('UTF-16LE', 'utf-8', $DataFromJDE);

got the clue from this answer by reverse engineering a bit https://stackoverflow.com/a/51130953/11835221

AND Voila! I got my Arabic data!

Hoping this helps another hair pulling soul some day.

Cheers!