[英]MySQL UTF-8 error using Zend Framework 2
I have a zf2 project that records clients informations in a mysql database. 我有一个zf2项目,该项目将客户端信息记录在mysql数据库中。 My DB is configured with
utf8
charset and utf8_unicode_ci
. 我的数据库配置了
utf8
charset和utf8_unicode_ci
。
My ZF2 global.php
is this 我的ZF2
global.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',
),
),
);
In the browser, when i submit the inputs, it goes to a ZF2 error "Statement could not be executed"
and next SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\\xE3' for column 'column' at row 1
在浏览器中,当我提交输入时,它会出现ZF2错误
"Statement could not be executed"
和下一个SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\\xE3' for column 'column' at row 1
Sorry if this question have already been answered, but i didnt find an answer, i hope you can help me. 抱歉,如果您已经回答了这个问题,但是我没有找到答案,希望您能帮助我。
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\''
),
) );
This is correct config from global and work for me 这是来自全局的正确配置,可以为我工作
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"
),
),
);
my friend helped me 我朋友帮了我
The solution was to set utf8_encode($data)
before recording, and utf8_decode($data)
in the view 解决方案是在录制之前设置
utf8_encode($data)
,并在视图中设置utf8_decode($data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.