Chinese Characters with Propel ORM

After walking through the Propel ORM tutorial on building a project my app could not display Chinese characters (UTF-8) correctly. Instead of characters I was getting “????”. I confirmed the columns in the DB were in UTF-8 format and viewed the data in another program – it checked out ok. I double checked the database encoding/collation and it was correctly set to UTF-8/Unicode. The individual table and column were also set for UTF-8 – its important to check this since some MySQL installations may default to latin1 which will not work with any non-english characters.

The solution for my problem turned out to be adding a few lines in the runtime-conf.xml file. The build tutorial in the Propel tutorial shows a standard runtime-conf.xml file but does not include an optional configuration parameter for the encoding on the DB connection. Below is the standard file with the encoding option added for UTF8 in bold:

<?xml version="1.0" encoding="UTF-8"?>
  <!-- Uncomment this if you have PEAR Log installed
    <datasources default="bookstore">
      <datasource id="bookstore">
        <adapter>mysql</adapter> <!-- sqlite, mysql, mssql, oracle, or pgsql -->
            <setting id="charset">utf8</setting>

After the making the above changes I could get Chinese characters correctly displaying in my app.