Re: Oracle10 e PHP

From: Gerard H. Pille <ghp_at_skynet.be>
Date: Tue, 24 Feb 2009 20:09:25 +0100
Message-ID: <49a445e5$0$2865$ba620e4c_at_news.skynet.be>


Daniele schreef:
> "Gerard H. Pille" <ghp_at_skynet.be> ha scritto nel messaggio
> news:49a2fa7a$0$2858$ba620e4c_at_news.skynet.be...

>> What is the character set of your database?    To contain those 
>> characters, it should be MSWIN1252 or one of the UTF's.
>>
>> What is the NLS_LANG setting of your PHP environment?   "phpinfo();" 
>> should be able to tell you.

>
> Phpinfo:
> NLS_LANG: american_america.WE8MSWIN1252
> NLS_NCHAR_CHARACTERSET: AL16UTF16
> (SetEnv directive in httpd.conf)
>
> Oracle:
> SELECT * FROM NLS_DATABASE_PARAMETERS:
>
> PARAMETER VALUE
> ------------------------------ ----------------------------------------
> NLS_NCHAR_CHARACTERSET AL16UTF16
> NLS_LANGUAGE AMERICAN
> NLS_TERRITORY AMERICA
> NLS_CHARACTERSET WE8MSWIN1252
>
> But now I found where is the problem.
> The field is a VARCHAR2 with size 254 (I cannot modify it, or NLS settings,
> since it's a third-party appliance).
> PHP returns an empty string ONLY IF the field is full (with all 254
> characters) and contains "smart quotes".
> I have infact read
> (http://shiflett.org/blog/2005/oct/convert-smart-quotes-with-php#comment-13)
> that smart quotes (ASCII 0x91, 0x92, 0x93, 0x94) are converted from 1 byte
> to 3 bytes, and I think that the resulting string (>254 charachters) is bad
> read by PHP.
> (N.B.: The conversion function showed in the link doesn't resolve the
> problem, because the string is already null...).
>
> Daniele
>
>

Try setting the environment before starting Apache, eg. in apachectl, not using SetEnv.

[Quoted] [Quoted] The conversion from 1 to 3 bytes is because sql*net thinks the client uses a different characterset than the database, probably UTF.

Do you specify a characterset in the oci_connect?

$c = oci_connect("hr", "hrpwd", "localhost/XE", 'AL32UTF8');

I found this in http://www.oracle.com/technology/tech/php/pdf/underground-php-oracle-manual.pdf:

$s = oci_parse($c,

             "select sys_context('userenv', 'language') as nls_lang from dual"); oci_execute($s);
$res = oci_fetch_array($s, OCI_ASSOC);
echo $res['NLS_LANG'] . "\n"; Received on Tue Feb 24 2009 - 20:09:25 CET

Original text of this message