Answer the question
In order to leave comments, you need to log in
How to set the encoding for the second database in Yii?
Good afternoon.
I'm trying to set up a connection to the second database in the yii config:
'db2'=>[
'class' => 'CDbConnection',
'connectionString' => 'mysql:host=localhost;dbname=table2',
'emulatePrepare' => true,
'username' => 'user',
'password' => 'pass',
'charset' => 'utf8',
],
Yii::app()->db2->createCommad()->select('title')->from('news')
Russian text is returned as question marks. 'db2'=>[
to 'db'=>[
, thenYii::app()->db->createCommad()->select('title')->from('news')
outputs the text in the correct encoding.
Answer the question
In order to leave comments, you need to log in
it is strange that it returns, because the command is written incorrectly.
do you display the same selections on the same page in the browser? most likely you have a problem with the fact that the charset for the page is not the one in the second database. therefore, everything is fine with the first database (utf-8 both in the database and in the browser), but with the second problem (utf-8 in the browser, but the text that you get from the database is in custom encoding)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question