PHP, Oracle and encodings

As I had previously posted I’m involved in several PHP-Oracle projects.

One involves ecommerce.

We’re doing this ecommerce for Latin America so it should handle special characters such as accents, ñ and others. Web page encoding is iso8859-1.

Every time a user made an insert, the database was recording a ‘?’ character instead of accents or other latin chars.

We tested for utf8_encode and utf8_decode functions, they were useless so we figured it out that the database was storing info in some other encoding. We added apache conf and meta headers to view the page as utf8 but again garbagge was being stored.

We were really angry so we started googling for some answers.

First of all we needed to know what encoding was the database using. We found out with the following query:

select * from NLS_DATABASE_PARAMETERS;

We got this from here.

After that we understood that we needed to enable the proper encoding for Oracle and PHP, how did we do it?

After a while we ended here.

So the solution was very simple. We added the following line to the main conf file:

putenv(“NLS_LANG=AMERICAN_AMERICA.AL32UTF8”);

After that we added utf8_encode and utf8_decode to the code and voilá! everything is working fine!

It was indeed a very exhausting work to figure this out so I’m posting it here to have a quick access to the solution.

Tags: ,

Comments are closed.