Answer the question
In order to leave comments, you need to log in
MS SQL Server, PHP and UTF-8
There was a task to receive the data from SQL Server in PHP.
Everything would be fine, but the MSSQL encoding is SQL_Latin1_General_CP850_CI_AS.
You need to receive data in UTF-8.
I assume two ways:
— Existence of a tablet of a type SET NAMES UTF-8. Does something similar exist in MSSQL?
- COLLATE each column at query time. COLLATE into what? I found collation lists, but did not see anything similar to Unicode.
Now the received data looks like question marks and it is not possible to choose an encoding for iconv for this case, and I would not want to do it through iconv.
ps SQL Server 8.0 - if I'm not mistaken, this is the two thousandth.
Answer the question
In order to leave comments, you need to log in
By the way, what driver are you using?
I have no problems with UTF-8 when using SQL Server Driver for PHP. True, I use SQL Server 2008, but this driver must be compatible with 2000, emnip.
you can collate to CYRILLIC_GENERAL_CI_AS and then iconv("cp1251", "UTF-8", $value)
You won't believe it... :-)
The problem was that I installed Native Client from 2005 server. I don’t know where I was looking :-0
I installed it from 2008 - everything started up.
With this driver, everything works as if there were no problems with encodings. Requests with utf8 conditions, responses are also in utf8.
And according to the link about Yii, due to the Yii bug / feature, the author will not receive some specific methods for MS SQL. Still, Yii doesn’t know about sqlsrv in some places yet, we should tell them ...
Many thanks to everyone!
If Latin1 is the standard encoding of the database, but the data in it must be stored and written in UTF-8, then in PHP code after connecting to the database it should help:
mysql_query('SET character_set_database = utf8');
mysql_query('SET NAMES utf8');
Support from Microsoft usually answers well. Try writing to your office.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question