Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSSQL Query issue in PHP and querying text data

Tags:

php

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.

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

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

like image 535
megazoid Avatar asked Mar 24 '11 04:03

megazoid


1 Answers

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.

like image 161
Phil Avatar answered Oct 04 '22 07:10

Phil