I stumbled upon an odd error using PHP's ODBC functions to query a SQL Server 2005 database. I was doing a basic SELECT statement to get the description of something when I encountered the following error:
我偶然发现了使用PHP的ODBC函数查询SQL Server 2005数据库的奇怪错误。 遇到以下错误时,我正在执行基本的SELECT语句来获取某些内容的描述:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [unixODBC][FreeTDS][SQL Server]Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier., SQL state in SQLExecDirect in /home/web/file.php on line 4
It turns out that the PHP ODBC functions have a hard time pulling "nvarchar" data. Here's the ugly solution to getting nvarchar data:
事实证明,PHP ODBC函数很难提取“ nvarchar”数据。 这是获取nvarchar数据的丑陋解决方案:
SELECT CAST(CAST([DetailedDescription] AS VARCHAR(8000)) AS TEXT) AS ad FROM mytable WHERE active = 1
Not pretty but making it function is what counts.
不漂亮,但使其发挥作用才是关键。