2

I have a problem with regional string characters inserted to MS SQL Server database.

There is a PHP application that connects with mssql server and inserts some data. But instead of inserting characters such as: ą, Ą, ć, Ł, ź (and so on - btw. these are polish regional characters), when inserted into mssql table they appear as a, A, c, L, z.

Here is some background:

  • I use freetds drivers for mssql connectivity
  • column type is nvarchar(MAX)
  • I looked at data sent "trough wire" (with WireShark) and the UTF-8 encoded data looks ok, for example Ą is sent as U+0104.
  • When inserting same string into local database instance (Microsoft SQL Server Express Edition) it works fine, but on remote host (in customer location - it is Microsoft SQL Server Standard Edition 64-bit) this "de-regionalization" occurs.

It seems like this remote mssql server doesn't handle this input data sent by php application right. Can anyone see/know what can be wrong here?

2
  • What's the datatype of the target database column? Commented Sep 15, 2010 at 15:54
  • EDIT: column type is nvarchar(MAX) Commented Sep 15, 2010 at 16:00

2 Answers 2

3

Maybe a rookie mistake, but I found the source of this problem according to KB #239530:

"When SQL Server converts a Unicode string without the N prefix from Unicode to the SQL Server database's code page, any characters in the Unicode string that do not exist in the SQL Server code page will be lost."

I suppose the local instance of sqlserver in some way treats all incoming string literals as Unicode strings and that remote server doesn't, thus requiring N prefix.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use this workaround, use htmlentities function before insert to database and html_entity_decode function after retrieve data from database. You can use ISO-8859-2 or Windows-1250 charset.

1 Comment

It want help, I don't retrieve data from this table, I only write into it and the other system uses it (not for html/www presentation).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.