PHP中的MSSQL查询问题和查询文本数据 [英] MSSQL Query issue in PHP and querying text data

查看:124
本文介绍了PHP中的MSSQL查询问题和查询文本数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP查询以连接和从MSSQL EXPRESS(2008 R2)数据库中提取数据.但是当我从数据库中提取基于ntext的数据时出现错误.

I'm trying a query in PHP to connect and extract data from a MSSQL EXPRESS (2008 R2) database. But i'm getting an error when i'm pulling ntext based data from the DB.

错误是;

仅Unicode归类或ntext数据中的Unicode数据无法使用DB-Library(例如ISQL)或ODBC 3.7或更早版本发送给客户端. (严重级16)在

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. (severity 16) in

我的脚本是

    $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 ....

谢谢....

推荐答案

来自mssql_query()

  • SELECT CAST(field1 AS TEXT) AS field1 FROM table
  • /etc/freetds.conf中的版本从4.2更改为8.0(如果PHP服务器为* nix)
  • 避免SELECT *查询
    • SELECT CAST(field1 AS TEXT) AS field1 FROM table
    • Chang the version in /etc/freetds.conf from 4.2 to 8.0 (if the PHP server is *nix)
    • Avoid SELECT * queries

    如果您在该页面上搜索ntext,则更多.

    Plenty more if you search ntext on that page.

    这篇关于PHP中的MSSQL查询问题和查询文本数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆