Hi,
I have problems with getting data out of the MS SQL Server 7.0 database in right encoding using odbc connection:
$conn = odbc_connect("Driver={SQL Server};Server=$server;Database=$database; CharacterSet => UTF-8", $user, $password);
I had the same problem when I used MS SQL Server 2005 and sqlsrv connection, but I found the solution. 'CharacterSet' => 'UTF-8' did the work and everything was fine in above connection it changes nothing:
$connectionInfo = array("Database" => ini_get("odbc.default_db"), "UID" => ini_get("odbc.default_user"), "PWD" => ini_get("odbc.default_pw"), 'CharacterSet' => 'UTF-8');
$conn = sqlsrv_connect($serverName, $connectionInfo);
I am stuck for 2 days now and desperate, i have looked all over google, php and ms forums and tried lot of solutions, none of them work.
I can't change anything in database as it's client db. Right now I just whant to get data out of one column (type= text), in this text column client stores html documents in windows-1257 charset (Latvian language), and when I select data from db all latvian characters (ēūīāšķļžčņ) are displayed as (euia??????).
I have tried to change parameters:
- ini_set('default_charset', 'utf-8');
- ini_set('mssql.charset', 'utf-8');
- iconv_set_encoding("input_encoding", 'utf-8');
- iconv_set_encoding("internal_encoding", 'utf-8');
- iconv_set_encoding("output_encoding", 'utf-8');
- ini_set("mbstring.internal_encoding", 'utf-8');
- ini_set("mbstring.script_encoding", 'utf-8');
- ini_set("mbstring.language",'Latvian');
Also tried to change the encoding of the string i get from db using comands:
- iconv
- mb_convert_encoding
- utf8_encode
The statement
$sql = "SELECT TOP 10 'ēūīāšķļņžč' t, TEKSTS FROM VESTURE WHERE TEKSTS IS NOT NULL";
echo $sql . '</br>';
$stmt = odbc_exec($conn, $sql);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
while ($row = odbc_fetch_row($stmt)) {
echo odbc_result($stmt, "t")."</br>".odbc_result($stmt, "TEKSTS") . "</br>";
}
Returns
ēūīā�?ķļņž�?
...
3. Katra civiltiesiska attieciba apsprie�ama pec likumiem, kas biju�i speka tad, kad �i attieciba radusies, pargrozijusies vai izbeigusies. Neskartas paliek jau iegutas tiesibas.
...
Insted of
ēūīāšķļņžč
....
3. Katra civiltiesiskā attiecība apspriežama pēc likumiem, kas bijuši spēka tad, kad šī attiecība radusies, pārgrozījusies vai izbeigusies. Neskartas paliek jau iegūtas tiesības.
...
When i put N front of 'ēūīāšķļņžč' it returns value as it have to:
SELECT TOP 10 N'ēūīāšķļņžč' t, TEKSTS FROM VESTURE WHERE TEKSTS IS NOT NULL
Returns
ēūīāšķļņžč
...
3. Katra civiltiesiska attieciba apsprie�ama pec likumiem, kas biju�i speka tad, kad �i attieciba radusies, pargrozijusies vai izbeigusies. Neskartas paliek jau iegutas tiesibas.
...