MSSQL Query issue in PHP and querying text data

前端 未结 3 1724
遥遥无期
遥遥无期 2020-12-04 18:21

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.

相关标签:
3条回答
  • 2020-12-04 18:43

    Couple of options from the comments on the mssql_query() manual page

    • 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

    Plenty more if you search ntext on that page.

    0 讨论(0)
  • 2020-12-04 18:45

    Here are some things you might need to know:

    1. Install mssql support for Debian (Lenny/Squeeze):

      apt-get install php5-sybase

    2. 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."

      In /etc/freetds/freetds.conf add these two lines (last two):

      [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): ; Specify client character set.. ; If empty or not set the client charset from freetds.comf is used ; This is only used when compiled with FreeTDS

      mssql.charset = "UTF-8"
      
    3. Use nchar/nvarchar/ntext column types if you need unicode support.

    0 讨论(0)
  • 2020-12-04 18:49

    In my case, I needed to install:

    sudo apt-get install php-sybase
    

    And modify the /etc/freetds.conf file:

    ...
    [global]
        # TDS protocol version
    ;   tds version = 4.2
    tds version = 8.0
    client charset = UTF-8
    ...
    
    0 讨论(0)
提交回复
热议问题