1

I am using ODBC connection to access a SQL Server database and get string from it. The problem is that I get ? symbols in string where for example it should be ē.

This is the code I am using:

if(($result = odbc_exec($connect, $sql)) !== false) {
   while( $obj = odbc_fetch_object( $result )) {
      if ($obj->PLK_STATUSS == '10') {
            echo $obj->DESCRIPTION;
       }
    }
}

It should echo Piemērs but what I get is Piem?rs.

I have put

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

in head. I also tried

echo utf8_decode($obj->DESCRIPTION);

with no luck.

What else could be a problem? I'm not experienced in php so probably it is something simple.

EDIT: If I just do echo "Piemērs"; then it works.

EDIT: Im using FreeTDS to create ODBC connection. My guess is that problem is with ODBC configuration. From other sources I got that in freetds.conf file there should be line

client charset = UTF-8

But when I add this line web page stops working and I get ERR_EMPTY_RESPONSE in browser.

2 Answers 2

1

Problem is probably because of newer php version. Had the same problem where ODBC worked in php5 but when upgraded to php7 had to change it to PDO.

Sign up to request clarification or add additional context in comments.

Comments

1

I managed to solve it changing from ODBC to PDO.

$conn = new PDO('dblib:charset=UTF-8;host='.Configure::read('SERVERNAME').';dbname='.Configure::read('DB'),
            Configure::read('USERNAME'),
            Configure::read('PASSWORD')
        );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.