MSSQL UTF8 string passed to ServicedComponent(COM+) but output becomes big5 when displayed using PHP

StackOverflow https://stackoverflow.com/questions/17430237

Вопрос

I stored my data in my MSSQL as UTF8 (I'm sure it is UTF8) and I use visual studio debug tool and I can see my string as UTF8 (because certain character only exit in UTF8, not big5), but after I use PHP to display my data through IIS fastCGI, the result is big5!.

I build a simple class to test it. You can try it.

using System.EnterpriseServices;
using System.Runtime.InteropServices;

namespace CoreService.HTML
{
    public interface ICore
    {        
        string get_string();
    }

    public class Core : ServicedComponent, ICore
    {
        public string get_string()
        {
            return "堃";
        }    
    }

}

If you get the character instead of ?? then you get it right. But I always get big after I call the COM+ in my PHP. I try apache and it is still the same thing.

UPDATE:

PHP sample code:

$object =  new COM("CoreService.HTML.Core") or die("Unable to instantiate CoreService COM object");
echo $object->get_string();

COM+ installation batch file: (install.bat)

cd\
c:
cd C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\
gacutil /i "c:\Fashion DLL\CoreService.dll"
echo install CoreService.dll Done
cd\
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
regsvcs /u "c:\Fashion DLL\CoreService.dll"
regsvcs "c:\Fashion DLL\CoreService.dll"
echo FashionCoreService done

in case you want to retry, you can use this to uninstall tlb file or the file is locked by IIS or apache:

cd\
c:
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
regsvcs /u "c:\Fashion DLL\CoreService.dll"
regasm /u "c:\Fashion DLL\CoreService.dll"
echo remove FashionCoreService done
iisreset
del "c:\Fashion DLL\CoreService.tlb"
pause
Это было полезно?

Решение

I found the solution.

$object = new COM("CoreService.HTML.Core", null, 65001) or die("Unable to instantiate CoreService COM object"); echo $object->get_string();

the third parameter is the codepage parameter, just assign 65001 (utf-8) then PHP will connect COM using UTF-8.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top