How to make PDO run SET NAMES utf8 each time I connect, In ZendFramework

后端 未结 8 821
迷失自我
迷失自我 2020-11-28 04:11

How to make PDO adapter run SET NAMES utf8 each time I connect, In ZendFramework. I am using an INI file to save the adapter config data. what entries should I add there?

相关标签:
8条回答
  • 2020-11-28 04:47

    In your bootstrap file...

    $db = Zend_Db::factory($adapter, $config);
    $db->query("SET NAMES 'utf8'");
    

    then you save this instance in your registry

    Zend_Registry::set('db', $db);
    
    0 讨论(0)
  • 2020-11-28 04:50

    fear my google-fu

    $pdo = new PDO(
        'mysql:host=mysql.example.com;dbname=example_db',
        "username",
        "password",
        array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
    

    first hit ;)

    0 讨论(0)
提交回复
热议问题