发新话题
打印

symfony如何改变数据库连接字符集

symfony如何改变数据库连接字符集

比如使用UTF-8,在filters.yml写上:

myUtf8ConnectionFilter:
class: myUtf8ConnectionFilter
activate: on

在app的lib目录添加一个myUtf8ConnectionFilter.class.php
复制内容到剪贴板
代码:
<?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();
  }
}
?>

TOP

发新话题