简体   繁体   English

使用Freetds,PHP,SQL Server,ADODB,并且无法传递UTF-8中具有某些特殊字符的数据

[英]Using Freetds, PHP, SQL Server, ADODB and not being able to pass data that has certain special characters in UTF-8

Ok, so here is my setup. 好的,这是我的设置。 I am working on a PHP application, which is on a linux OS. 我正在Linux系统上的PHP应用程序上工作。 I am trying to pass data over to a Windows OS, into a SQL Server database. 我正在尝试将数据传递到Windows操作系统和SQL Server数据库中。 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. 我使用Freetds充当提供者,因为这似乎是每个人都用来从Linux机器与SQL Server进行通信的方式。 I am using ADODB which is a Database Abstraction Library for PHP. 我正在使用ADODB,它是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. 我将所有这些数据都收集起来,然后将其传递给第三方系统,这是我之前在其中提到的SQL Server实例。

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. 我花了几个小时才发现它不是PHP,不是我的应用程序,也不是我的代码,因为特殊字符即使在调试adodb方法中传递给存储过程参数的内容时,也能在过程的所有点正确显示。 The problem was in FreeTDS as I found I needed to add the following line to my freetds.conf 问题出在FreeTDS中,因为我发现需要将以下行添加到我的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. 经过在吉拉(Jira)关闭任务后的进一步测试,我以为我再也不必为此担心了,我收到一封电子邮件,说嘿,这在罗马尼亚各州均不起作用。 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 我不太了解字符集,我确实读过每个开发人员都应该了解的Joels Absolute Minimum

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. 在罗马尼亚的状态是不工作的一个例子是Și la o răspântie cu statui ,我认为这是Ș性格这就是问题所在。 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 在SQL Server上运行查询时,它仅将其转换为S。在php中执行并通过freetds发送时,它将返回此错误消息

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. 我已经尝试在执行查询之前设置SET names UTF8和其他一些SET names UTF8 ,但我认为问题还是出在查询之前freetds没有传递正确的字符。

问题在于当前数据库仅接受varchar而不接受nvarchar,因此我必须让第三方支持nvarchar或进行某种类型的映射以获取等价的ascii。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM