MSSQL+unicode
Posted: Tue Dec 14, 2004 12:30 pm
Hello,
I've spent long hours trying to solve this, digged up all the net to no avail.
Here's the setup:
I am using MSDE 2000a version for the database. It's basically MSSQL server 2000, but bared to the db engine only. The testing is done on WinXP PC. PHP version 4.3.9.
I have made one database with one table with one field of nvarchar type. My goals are as follow:
1) Be able to properly read the unicode text string from the database, and be able to display if using PHP, outputting the web page with utf-8 encoding.
2) Be able to write any unicode string (say, I' d have utf-8 encoded string in my hands) to the database.
I am still struggling with the first one. The problem appears to be in the fact, that the character data are being converted using certain encoding, and when they get to the PHP, they are available in that encoding. To my tests, this encoding is derived from the database field collation setting. Unfortunately that means, that while I can easily store characters from multiple charsets in the field (using Enterprise Manager, table open), my opportunitie to read the whole data are limited by the collation setting of this field.
I don't have idea how those other (who are able to read/write unicode data)client tools connect to the MSSQL server, but that just proves that there is a way. It may seem appropriate to expect some kind of method that would allow to set the encoding for PHP-SQLserver communication. That would allow to read/write queries with unicode characters, and that would solve most of the problems. Unfortunately, I couldn't find one.
The next thing I will have to face is, when everything will be looking smooth on my WinXP box, I will have to put the stuff on the online site, which is hosted on Linux server. And that another issues may arise. But let's solve problems one-by-one.
I've spent long hours trying to solve this, digged up all the net to no avail.
Here's the setup:
I am using MSDE 2000a version for the database. It's basically MSSQL server 2000, but bared to the db engine only. The testing is done on WinXP PC. PHP version 4.3.9.
I have made one database with one table with one field of nvarchar type. My goals are as follow:
1) Be able to properly read the unicode text string from the database, and be able to display if using PHP, outputting the web page with utf-8 encoding.
2) Be able to write any unicode string (say, I' d have utf-8 encoded string in my hands) to the database.
I am still struggling with the first one. The problem appears to be in the fact, that the character data are being converted using certain encoding, and when they get to the PHP, they are available in that encoding. To my tests, this encoding is derived from the database field collation setting. Unfortunately that means, that while I can easily store characters from multiple charsets in the field (using Enterprise Manager, table open), my opportunitie to read the whole data are limited by the collation setting of this field.
I don't have idea how those other (who are able to read/write unicode data)client tools connect to the MSSQL server, but that just proves that there is a way. It may seem appropriate to expect some kind of method that would allow to set the encoding for PHP-SQLserver communication. That would allow to read/write queries with unicode characters, and that would solve most of the problems. Unfortunately, I couldn't find one.
The next thing I will have to face is, when everything will be looking smooth on my WinXP box, I will have to put the stuff on the online site, which is hosted on Linux server. And that another issues may arise. But let's solve problems one-by-one.