Oracle database showing mystery characters after inserting data with Symfony and Propel
Posted in Oracle, PHP, Symfony on December 12th, 2011 by Joonas – Be the first to commentInterfacing with third party data feeds and loading data to your own database happens all over the business world. Whether you are loading data from an XML, CSV, or TXT file, every now and then you will run in to that annoying mystery character error. You’ve written your code to read your XML file and insert rows in to your database, but when you go check the data that was inserted with SQL Developer (or your program of choice), you notice that some characters have been turned in to mysterious black boxes with white question marks. The problem is with encoding multi-byte characters.
You need to make sure that your database and tables are created with UTF-8 encoding. The second step is to make sure that your database connection from Symfony/Propel is made using UTF-8 encoding as well. In your database.yml file, you need to specify the encoding.
The yml for your connection should look something like:
prod:
propel:
class: sfPropelDatabase
param:
phptype: oracle
hostspec: (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)))(CONNECT_DATA = (SID=YOUR_DB_SID)))
username: YOUR_DB_USERNAME
password: YOUR_DB_PASSWORD
encoding: utf8Run your script again and import data with the right encoding. Your mystery characters should go away from your database. Enjoy.
Those of you who stumbled upon this post with the same problem, but are not using Symfony and/or Propel, the theory is the same. If you are just using PHP’s PDO to connect to MySQL or another database abstraction layer of your choice, the above steps still apply. First, make sure your database uses the right encoding and that your tables are created with it as well. Second, make sure your database connection from PHP is established with the UTF-8 encoding. It makes all the difference.
Having problems connecting to your Oracle database with Symfony?
Check out my previous post about the matter: Connecting to an Oracle 11g database with Symfony 1.0 & Propel