Search code examples
phpsymfonyt-sqlencodingsap-ase

Garbled Data from sybase to php


I am trying to get a Binary(12) value from a Sybase ASE database with Symfony2 and php 5.6 , I've read the doc and tried many methods but still can't get this working.

I struggled to get the connection to work, it works now using FreeTDS but when I make a simple select query with php I get a garbled string ÿÿÿÿ????X ( I'm expecting to get an hexadecimal number like ffffffff000000000001587f) although when I make the same query with isql I get the correct output.

I'm not sure if the problem comes from different encoding between the Database and PHP because both PHP and TSQL uses the TDS protocol with UTF-8 encoding.

The code I'm using in my project to get the data:

    $em = $this->get('doctrine')->getManager('qualif');
    $connection = $em->getConnection();
    $statement = $connection->prepare("select max(account_oidval) from ACCOUNT");
    $statement->execute();
    $results = $statement->fetchColumn();

I've tried to convert encoding with this but still fails to get the correct format

    $resultInUTF8 = mb_convert_encoding($results,"UTF-8","ISO-8859-1");

Solution

  • Try this:

    "select bintostr(max(...)) ....".