![]() |
|
Snippets |
|
Since it can be annoying to have Propel ignore collation of tables in MySQL >= 4.1, you must force Propel to use UTF-8 collation by running the SET NAMES UTF8 SQL query.
In order to do that, you specify a filter that executes at every request. Specify the following code in filters.yml:
myUtf8ConnectionFilter: class: myUtf8ConnectionFilter activate: on
Create a new file called myUtf8ConnectionFilter.class.php in your application's lib folder and insert the following code:
<?php class myUtf8ConnectionFilter extends sfFilter { public function execute($filterChain) { $con = Propel::getConnection(); if ($con){ $con->executeQuery("set names utf8"); } else { throw new Exception($e); } $filterChain->execute(); } } ?>
The code was copied from this website - I am not asserting any authorship.
Comments on this snippet
Or you can just add this to the mysql configuration file (my.ini or my.cnf): init-connect="SET NAMES utf8" (but beware not to use root user...)
If you use more than one database and modification of mysql config file could be problem, You may take a look at code below - it's a modified version of above snippet:
class myUtf8ConnectionFilter extends sfFilter {
}
In symfony > 0.9.2136, you can add an encoding parameter in your databases.yml configuration file.
I'm running symfony 1.0.12 but the encoding parameter in databases.yml isn't working for me. I've set it to utf8 but my tables still end up with a collation of latin1_swedish_ci .
I'd be grateful for any advice you can offer.