M
M
MastaEx2011-05-24 15:31:11
PHP
MastaEx, 2011-05-24 15:31:11

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

7 answer(s)
P
pietrovich, 2011-05-26
@MastaEx

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.

P
plaha, 2011-05-25
@plaha

you can collate to CYRILLIC_GENERAL_CI_AS and then iconv("cp1251", "UTF-8", $value)

M
MastaEx, 2011-05-26
@MastaEx

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!

M
MrCrock, 2011-05-24
@MrCrock

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');

G
garrich, 2011-05-24
@garrich

Support from Microsoft usually answers well. Try writing to your office.

L
lavel, 2011-05-25
@lavel

What type of columns are they? MSSQL stores data in unicode using UCS2 for NCHAR, NVARCHAR, NTEXT. Try doing CAST as NVARCHAR for example, or create a table with that type and select from it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question