dbTalk Databases Forums  

Oracle10 e PHP

comp.databases.oracle.tools comp.databases.oracle.tools


Discuss Oracle10 e PHP in the comp.databases.oracle.tools forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Daniele
 
Posts: n/a

Default Oracle10 e PHP - 02-20-2009 , 01:58 AM






Hello to everyone,
I have a Oracle 10g Database Server on Suse Linux.
I want to read records with a PHP script on a Linux Red Hat 9 Server (with
Apache 2, PHP 5, and OCI8 functions).

But SELECTs of text records that contains non-standard chars return an emtpy
string.

For non-standard chars I mean quotes or apostrophes like these: ' " "
instead of: ' "

What do I have do set in my web server?

Thank you,
Daniele



Reply With Quote
  #2  
Old   
Álvaro G. Vicario
 
Posts: n/a

Default Re: Oracle10 e PHP - 02-20-2009 , 03:22 AM






Daniele escribió:
Quote:
I have a Oracle 10g Database Server on Suse Linux.
I want to read records with a PHP script on a Linux Red Hat 9 Server (with
Apache 2, PHP 5, and OCI8 functions).

But SELECTs of text records that contains non-standard chars return an emtpy
string.

For non-standard chars I mean quotes or apostrophes like these: ' " "
instead of: ' "

What do I have do set in my web server?
Quotes are quite standard... Are you dumping the results into HTML
without proper escaping?

If you actually meant non-English characters, find the "The Underground
PHP and Oracle® Manual" manual and check chapter 15 (Globalization). You
basically need to set an env variable in your Red Hat server.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--


Reply With Quote
  #3  
Old   
Daniele
 
Posts: n/a

Default Re: Oracle10 e PHP - 02-20-2009 , 05:09 AM



Sorry, I tried, but NG Server don't allow me to send in HTML.
Anyway, quotes and apostrophes are the ones "automatically modified" by
Word.

Daniele


""Álvaro G. Vicario"" <alvaro.NOSPAMTHANX (AT) demogracia (DOT) com> ha scritto nel
messaggio news:gnlso3$6sn$1 (AT) reader (DOT) motzarella.org...
Quote:
Daniele escribió:
I have a Oracle 10g Database Server on Suse Linux.
I want to read records with a PHP script on a Linux Red Hat 9 Server
(with
Apache 2, PHP 5, and OCI8 functions).

But SELECTs of text records that contains non-standard chars return an
emtpy
string.

For non-standard chars I mean quotes or apostrophes like these: ' " "
instead of: ' "

What do I have do set in my web server?

Quotes are quite standard... Are you dumping the results into HTML
without proper escaping?

If you actually meant non-English characters, find the "The Underground
PHP and Oracle® Manual" manual and check chapter 15 (Globalization). You
basically need to set an env variable in your Red Hat server.


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--




Reply With Quote
  #4  
Old   
Álvaro G. Vicario
 
Posts: n/a

Default Re: Oracle10 e PHP - 02-20-2009 , 05:40 AM



Daniele escribió:
Quote:
Sorry, I tried, but NG Server don't allow me to send in HTML.
I meant your application's HTML.


Quote:
Anyway, quotes and apostrophes are the ones "automatically modified" by
Word.
Right, those could be included in the "non-English characters"
definition for our purpose. Try the chapter I mentioned and tell us
whether it helped.


Quote:
I have a Oracle 10g Database Server on Suse Linux.
I want to read records with a PHP script on a Linux Red Hat 9 Server
(with
Apache 2, PHP 5, and OCI8 functions).
It doesn't make much sense to quote the question after the answer. Try
to keep your posts cleaner ;-)


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--


Reply With Quote
  #5  
Old   
Daniele
 
Posts: n/a

Default Re: Oracle10 e PHP - 02-23-2009 , 06:06 AM




""Álvaro G. Vicario"" <alvaro.NOSPAMTHANX (AT) demogracia (DOT) com> ha scritto nel
messaggio news:gnm4r9$imf$1 (AT) reader (DOT) motzarella.org...
Quote:
I meant your application's HTML.

The problem is before showhing data in HTML.

When I fetch rows with PHP functions, I get a null string if there are
"smart quotes" in the content.

The command:
echo strlen($row['FIELD_NAME']);
returns a 0 (or a number >0 when "smart quotes" are NOT present in the
content of the field).

But with ethereal I can see that the entire content of the field is received
by the web server, so the problem should be in PHP (ver. 5.0.4) and/or
Oracle libraries (instant client 10.1.0.4).

I tried to upgrade PHP, OCI or both, but for some reasons the compilation
fails.

Daniele




Reply With Quote
  #6  
Old   
Gerard H. Pille
 
Posts: n/a

Default Re: Oracle10 e PHP - 02-23-2009 , 01:35 PM



Daniele schreef:
Quote:
""Álvaro G. Vicario"" <alvaro.NOSPAMTHANX (AT) demogracia (DOT) com> ha scritto nel
messaggio news:gnm4r9$imf$1 (AT) reader (DOT) motzarella.org...
I meant your application's HTML.

The problem is before showhing data in HTML.

When I fetch rows with PHP functions, I get a null string if there are
"smart quotes" in the content.

The command:
echo strlen($row['FIELD_NAME']);
returns a 0 (or a number >0 when "smart quotes" are NOT present in the
content of the field).

But with ethereal I can see that the entire content of the field is received
by the web server, so the problem should be in PHP (ver. 5.0.4) and/or
Oracle libraries (instant client 10.1.0.4).

I tried to upgrade PHP, OCI or both, but for some reasons the compilation
fails.

Daniele



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.


Reply With Quote
  #7  
Old   
Daniele
 
Posts: n/a

Default Re: Oracle10 e PHP - 02-24-2009 , 06:24 AM




"Gerard H. Pille" <ghp (AT) skynet (DOT) be> ha scritto nel messaggio
news:49a2fa7a$0$2858$ba620e4c (AT) news (DOT) skynet.be...
Quote:
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/co...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




Reply With Quote
  #8  
Old   
Gerard H. Pille
 
Posts: n/a

Default Re: Oracle10 e PHP - 02-24-2009 , 01:09 PM



Daniele schreef:
Quote:
"Gerard H. Pille" <ghp (AT) skynet (DOT) be> ha scritto nel messaggio
news:49a2fa7a$0$2858$ba620e4c (AT) news (DOT) 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/co...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.

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/tec...le-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";


Reply With Quote
  #9  
Old   
Daniele
 
Posts: n/a

Default Re: Oracle10 e PHP - 02-25-2009 , 04:56 AM



Quote:
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');

Very strange thing.
In my oci_connect I already had the characterset among parameters.

Removing it ( $c = oci_connect("hr", "hrpwd", "localhost/XE"); ) the
conversion from 1 to 3 bytes doesn't happen anymore, and my initial problem
seems resolved.

Quote:
I found this in
http://www.oracle.com/technology/tec...le-manual.pdf:

Thank you for the manual, I'll read it.

Daniele




Reply With Quote
  #10  
Old   
Gerard H. Pille
 
Posts: n/a

Default Re: Oracle10 e PHP - 02-25-2009 , 12:18 PM



Daniele schreef:
Quote:
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');

Very strange thing.
In my oci_connect I already had the characterset among parameters.
"The" characterset? Which one was it?

Why do you find this strange? Specifying the character set with the oci_connect is said to
speed up connecting.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.