NVARCHAR support in MSSQL and EXEC statements / Help Please!

NVARCHAR support in MSSQL and EXEC statements

MSSQL direct (not ODBC)

I'm trying to do something like the below code where one NVARCHAR column is being returned in a SQL result set. The recordset has one column containing Chinese characters..

This way works

$result = $db→translatedQuery("SELECT….");

and I get back string(39) "chinese characters here omitted"

This doesnt work

$result = $db→translatedQuery("EXEC…");

and I get back string(13) "?????????????"

Do you have any pointers why the result set translate for the UTF-8/NVARCHAR column is not translated for EXEC?

Thanks

  • Message #379

    Unfortunately getting NVARCHAR/NCHAR/NTEXT data into PHP is a painful task. The translatedQuery() call is actually finding all of the national columns and altering the SQL to cast them to binary data. Once the data comes back, then the binary data is converted from USC-2LE (the native encoding for national columns in SQL Server) to UTF-8.

    You should be able to emulate this manually for an EXEC statement by adding appropriate CAST statements to the SQL and iconv() calls in the PHP.

    $result = $db->query('EXEC … CAST(ncolumn AS VARBINARY(MAX)) AS ncol');
    foreach ($result as $row) {
        $row['ncol'] = iconv('ucs-2le', 'utf-8', $row['ncol']);
        //
    }