0

我有一个在 mysql 数据库中记录客户信息的 zf2 项目。我的数据库配置了utf8charset 和utf8_unicode_ci.

我的ZF2global.php是这个

return array(
    'db' => array(
        'username' => 'root',
        'password' => 'root',
        'driver'   => 'Pdo',
        'dsn'      => 'mysql:dbname=atendimento;host=localhost',
        'charset'  => 'utf-8',
        'driver_options' => array(
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
        ),
    ),
    'service_manager' => array(
        'factories'   => array(
            'Zend\Db\Adapter\Adapter'
                      => 'Zend\Db\Adapter\AdapterServiceFactory',
        ),
    ),
);

在浏览器中,当我提交输入时,它会出现 ZF2 错误"Statement could not be executed",然后SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE3' for column 'column' at row 1

对不起,如果这个问题已经回答了,但我没有找到答案,我希望你能帮助我。

4

3 回答 3

1
return new \Zend\Db\Adapter\Adapter ( array (
                'driver' => 'pdo',
                'dsn' => "mysql:dbname=$config[Dbname];host=$config[host]",
                'username' => $config ['Dbuser'],
                'password' => $config ['Dbpassword'],
                'driver_options' => array(
                        \PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
                ),
        ) );
于 2014-09-28T13:15:25.810 回答
0

这是来自全球的正确配置,对我有用

return array(
    'db' => array(
        'driver'         => 'Pdo',
        'dsn'            => 'mysql:dbname=singclub;host=localhost;',
        'username'       => 'root',
        'password'       => '',
        'driver_options' => array(
                PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8"
        ),
    ),
);
于 2013-09-29T21:41:24.343 回答
-8

我的朋友帮助了我

解决方案是utf8_encode($data)在录制之前设置,并utf8_decode($data)在视图中

于 2013-09-18T17:48:25.633 回答