I use MS SQL.
Calling save() in ActiveRecord saves the data,
An nvarchar type item in the table, such as “あいうえお”
If you enter double-byte characters, it becomes “???”.
I have set “utf8” in charset
Is there anything else I should address?
I use MS SQL.
Calling save() in ActiveRecord saves the data,
An nvarchar type item in the table, such as “あいうえお”
If you enter double-byte characters, it becomes “???”.
I have set “utf8” in charset
Is there anything else I should address?
what happens if you insert same data on commandline or SSMS?
I’m sorry to be late
I haven’t tried SSMS yet,
I tried the following in DBeaver’s SQL editor.
INSERT INTO db.dbo.table
(name)
VALUES(‘あいうえお’);
In this case, it was still “???”.
INSERT INTO db.dbo.table
(name)
VALUES(N’あいうえお’);
When using this N prefix, it was registered as “あいうえお”.
What if you do the same with Yii?
Yii::$app->db->createCommand(“INSERT INTO db.dbo.table (name) VALUES(N’あいうえお’)”)->execute();
I tried this on Yii and it was registered correctly.
thank you!
Is it possible to save () double-byte characters in a class that inherits ActiveRecord?
Is there no choice but to INSERT directly?
try this
$model = MyModel();
$model->name = N’あいうえお’; //here do set same string like you did on direct insert
$model->save();
You might want to check some links if they can help!
https://chevronscode.com/index.php/php-how-to-insert-chinese-character-into-mysql.html
Check if you can accomodate those calls to connection configuration or after connection open event
sorry.
$model = MyModel();
$model->name = N’あいうえお’;
$model->save();
I failed with this
INSERT with createCommand().
Thank you very much.
Did it finally work?
Can you explain your final solution so that someone elese will benefit in the future?