如何查询 SQL Server 数据库并使撇号不显示为问号?
不幸的是,我正在使用基于 MSSQL 的数据源,并尝试将其集成到用 PHP 编写的自定义 Drupal 模块中。我的问题是,无论我使用哪种包装函数,我都无法让撇号正确显示在页面上。都变成了问号。此外,破折号也能起到同样的作用。
我知道这是一个编码问题。该页面采用 UTF-8 编码,但数据库采用 SQL_Latin1_General_CP1_CI_AS 编码。我无法控制数据库结构,也无法修改它。我无法选择更改数据库中的所有值。
我怎样才能以未损坏的形式访问这些数据,或者至少让 PHP 正确地吐出它?
我尝试过,但没有成功: utf_编码 utf_解码 html_entities 图标 几个自定义编码的 str_replace 函数 MSSQL 没有 SET NAMES 函数
救命!
Unfortunately I'm using a MSSQL-based data source and attempting to integrate it into a custom Drupal Module being written in PHP. My issue is that no matter what sort of wrapper function I use, I CANNOT get apostrophes to appear correctly on the page. They all turn into question marks. In addition, emdashes do the same thing.
I know this is an encoding issue. The page is encoded in UTF-8, but the database is encoded in SQL_Latin1_General_CP1_CI_AS. I have no control over the database structure and it cannot be modified. I do not have the option to change all the values in the database.
How can I access this data in uncorrupted form or at least get PHP to spit it out properly?
I have tried, without success:
utf_encode
utf_decode
html_entities
iconv
several custom coded str_replace functions
MSSQL doesn't have a SET NAMES function
Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过显式转换输出?例如:
根据 MSDN 上的排序规则和 Unicode 支持页面,Unicode支持 5.0,但您可能需要强制使用较新的 *_100 排序规则才能利用新功能。 另一页声称 SQL Server 不支持 UTF-8,但支持 UTF-16。
您可以使用内置 TVF 仔细阅读支持的排序规则的完整列表:
Have you tried explicitly casting the output? For example:
According to the Collation and Unicode Support page on MSDN, Unicode 5.0 is supported, though you may need to force the use of the newer *_100 collations to take advantage of the new features. Another page claims that SQL Server doesn't support UTF-8, but UTF-16 IS supported.
You can peruse the entire list of supported collations with a built-in TVF:
由于您使用的是不支持新排序规则的较旧版本的 SQL Server,因此您是否尝试将该数据转换为 NVARCHAR?
例如:
管理数据上有一个 MSDN 页面客户端/服务器代码页之间的转换提供了一些通用信息。一般来说,建议似乎集中在修改连接的细节或数据库结构(您说鉴于当前的限制这是不可能的)。具体来说,
As you're using an older version of SQL Server which doesn't support the new collations, have you tried to cast that data out as a NVARCHAR?
For example:
There is an MSDN page on Managing Data Conversion Between Client/Server Code Pages which provides some generic information. In general, the recommendation seems to center around modifying either the specifics of the connection or the database structure (which you said is not possible given current limitations). Specifically,