Ok, so here is my setup. I am working on a PHP application, which is on a linux OS. I am trying to pass data over to a Windows OS, into a SQL Server database. I am using Freetds to act as the provider since this is what it seems everyone uses to communicate with SQL Server from a Linux machine. I am using ADODB which is a Database Abstraction Library for PHP.
I am also developing a checkout system that allows a user to select any one of the hundreds of countries that exist as well as input the state or province of that country. I take all of this data and have to pass it over to a third party system, which is the SQL Server instance in which I talked about previously.
The problem is, users are entering data with special characters for their states/countries such as ö. It took me hours to find that it wasn’t PHP, my application, my code as the special characters came out correctly at all points of the process even when debugging what was being passed to the stored procedure param in the adodb method. The problem was in FreeTDS as I found I needed to add the following line to my freetds.conf
client charset = UTF-8
This appear to work and I was super happy that it actually wasn’t my code and just a single line in the configuration file. Upon further testing after my task was closed in Jira and I thought I would never have to worry about this again, I get the email saying hey this isn’t working for Romanian states. So it appears that not all special characters are being passed correctly.
I am not that knowledgeable on character sets, I did read Joels Absolute Minimum every developer should know about them
An example of a state in Romania that doesn’t work is Și la o răspântie cu statui where I think it is the Ș character that is the problem. When running the query on SQL server it just converts that to an S. When doing in php and sending over freetds it returns this error message
The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 9 ("@in_state_name"): Data type 0xA7 has an invalid data length or metadata length.
I have tried setting SET names UTF8 and a few others before doing the query but I think again the problem is before it even gets to the query freetds isn’t passing over the correct character.
The problem is that the current database only accepts varchar and not nvarchar so I have to either get the third party to support nvarchar or do some type of mapping to get an ascii equivelent.