Search code examples
phpsql-servercharset

Problem with national characters using the PHP function sybase_connect


I am using PHP function sybase_connect to connect to mssql database and retrieave data like this:

$mssql=sybase_connect($Host, $User, $Password, "cp1257");
$mssql->query("EXEC AuthLoginList");
while($mssql->get_row()){
  echo $mssql->f('id')." ".$mssql->f('name')." ".$mssql->f('surname')."<br>";
}

enter image description here

However, national symbols are incorrectly extracted. Questionnaires appear in their place: enter image description here

Database version is Microsoft SQL Server 2012 (SP4-GDR) (KB4583465) - 11.0.7507.2 (X64)

The following encodings are used for text fields:

enter image description here

enter image description here

It doesn't matter what encoding you use. The result is always the same. Question marks are provided instead of national symbols. Ex:

$mssql=sybase_connect($Host, $User, $Password, "cp1257");
$mssql=sybase_connect($Host, $User, $Password, "iso-8859-1");
$mssql=sybase_connect($Host, $User, $Password, "utf8");
$mssql=sybase_connect($Host, $User, $Password, "utf-8"); 
$mssql=sybase_connect($Host, $User, $Password, "iso_1");
$mssql=sybase_connect($Host, $User, $Password, "windows-1257");
$mssql=sybase_connect($Host, $User, $Password, "UNICODE");

Maybe someone could give me advice on how to solve this problem.


Solution

  • After a long reading of the TDS protocol documentation, I found a solution:

    > export LANG lt_LT
    

    By setting the environment variable LANG in this way, the MSSQL database in my nevironment obtains the correct encoding ISO-8859-13.

    enter image description here