[英]MSSQL Query issue in PHP and querying text data
I'm trying a query in PHP to connect and extract data from a MSSQL EXPRESS (2008 R2) database. 我正在尝试在PHP中进行查询以连接并从MSSQL EXPRESS(2008 R2)数据库中提取数据。 But i'm getting an error when i'm pulling ntext based data from the DB.
但是,当我从数据库中提取基于ntext的数据时遇到错误。
Error is; 错误是;
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.
只能使用Unicode排序规则或ntext数据的Unicode数据不能使用DB-Library(例如ISQL)或ODBC 3.7或更早版本发送给客户端。 (severity 16) in
(严重性16)在
and my script is 而我的剧本是
$myServer = ".\SQLEXPRESS";
$myUser = "sa";
$myPass = "blablabla";
$myDB = "test";
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
//declare the SQL statement that will query the database
$query = "SELECT * FROM dbo.table WHERE query='2'";
//$query .= "FROM dbo.table ";
//$query .= "WHERE query='2'";
//execute the SQL query and return records
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
//display the results
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["query"]. "</li>";
}
//close the connection
mssql_close($dbhandle);
any help on this is appreciated .... 在这方面的任何帮助表示赞赏....
Thanks .... 谢谢 ....
Couple of options from the comments on the mssql_query()
manual page mssql_query()
手册页上的注释中的mssql_query()
选项
SELECT CAST(field1 AS TEXT) AS field1 FROM table
/etc/freetds.conf
from 4.2 to 8.0 (if the PHP server is *nix) /etc/freetds.conf
的版本从4.2更改为8.0(如果PHP服务器是* nix) SELECT *
queries SELECT *
查询 Plenty more if you search ntext
on that page. 如果在该页面上搜索
ntext
,则更多。
Here are some things you might need to know: 您可能需要了解以下几点:
Install mssql support for Debian (Lenny/Squeeze): 为Debian(Lenny / Squeeze)安装mssql支持:
apt-get install php5-sybase apt-get安装php5-sybase
When you got this error message: "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." 当您收到此错误消息时:“仅使用Unicode排序规则或ntext数据的Unicode数据无法使用DB-Library(例如ISQL)或ODBC 3.7或更早版本发送给客户端。”
In /etc/freetds/freetds.conf add these two lines (last two): 在/etc/freetds/freetds.conf中添加以下两行(最后两行):
[global] ;tds version = 4.2 tds version = 8.0 client charset = UTF-8
You can edit "charset" in php.ini too (but you don't need if you did it previously in freetds.conf): ; 您也可以在php.ini中编辑“字符集”(但是如果您以前在freetds.conf中进行过编辑则不需要): Specify client character set.. ;
指定客户端字符集。 If empty or not set the client charset from freetds.comf is used ;
如果为空或未设置,则使用freetds.comf的客户端字符集; This is only used when compiled with FreeTDS
仅在与FreeTDS一起编译时使用
mssql.charset = "UTF-8"
Use nchar/nvarchar/ntext column types if you need unicode support. 如果需要unicode支持,请使用nchar / nvarchar / ntext列类型。
In my case, I needed to install: 就我而言,我需要安装:
sudo apt-get install php-sybase
And modify the /etc/freetds.conf file: 并修改/etc/freetds.conf文件:
...
[global]
# TDS protocol version
; tds version = 4.2
tds version = 8.0
client charset = UTF-8
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.