Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting Danish characters to sql server from PHP

When inserting danish characters to sql server to a field with an nvarchar datatype the danish characters get malformed. Example: brændstof is converted to brændstof. When it is directly from sql server query window it is working correctly. I tried giving different collations to that field(Latin1_Genaral,Danish_Greenlandic_100_CI_AI,Danish_Norwegian_CI_AI etc.) Is there a way to achieve this. I am using Microsoft Drivers 3.0 for PHP for SQL Server. Please help

like image 987
Ajmal VH Avatar asked Mar 07 '13 13:03

Ajmal VH


4 Answers

instead of a literal 'æ', use its CHAR equivalent and see what happens.

like image 97
Harish Anchu Avatar answered Sep 27 '22 21:09

Harish Anchu


I don't now what about Danish letters, but I had problem with Armenian in SQL SERVER. I solved this problem like this.

insert into sometable(field) values( N'myArmenianText' );
like image 29
Vahe Shadunts Avatar answered Sep 27 '22 20:09

Vahe Shadunts


I used a work around, just html encoded the danish string before insering into table, and when displaying just decoded back

like image 41
Ajmal VH Avatar answered Sep 27 '22 21:09

Ajmal VH


Just as guess here:

I think the problem is in the PHP part, not in the MySQL part (I read you used some encoding for that field specifically for Danish). Or even earlier. Ever tried to put an 'ä' on an HTML page (the real character, not ä)? It gets converted to some other chars like the example in your question. So I see two possibilities here:

  • User input is incorrectly URl-encoded
  • PHP uses some encoding that doesn't support Danish characters.

Or perhaps 3 & 4 (less likely):

  • The char arrives incorrectly at the client (if you resend some chars to the server I don't know if that's the case)
  • The user agent converts the chars and thus sends malformed chars to the server (or displays them wrong, which would mean the right chars are on the server, but you can't view them with your browser)
like image 26
11684 Avatar answered Sep 27 '22 20:09

11684