3

I have one table in MSSQL Server 2012 whose data type of one column is defined as below:

COLUMN_NAME   DATA_TYPE   TYPE_NAME   COLUMN_SIZE
description   2005        nvarchar    1073741823

When I run this query:

select * from tablename

using PHP PDO then I don't get any result. And if I write names of all fields in above sql select query excluding this field then I am getting result.

What is wrong with this data type?

Note: this table is directly imported from MySQL by using some tool.

I have googled a lot but could not get any solution.

gofr1
  • 15,741
  • 11
  • 42
  • 52
Neeraj
  • 8,625
  • 18
  • 60
  • 89
  • Maybe this is a similar issue and casting it would work? http://eugenioz.blogspot.com/2013/07/php-mssql-nvarchar-fetch-and-write-utf.html – chris85 Apr 16 '15 at 12:51
  • It worked by using solution given at your suggested URL !!! – Neeraj Apr 16 '15 at 12:57
  • Great. You may want to post the solution from that link (or what you did) as an answer to so others that find this thread can resolve their issues as well. – chris85 Apr 16 '15 at 13:07
  • It would be great if you post that solution as an answer and i would like to upvote and accept it – Neeraj Apr 16 '15 at 13:17

1 Answers1

3

The solution on this website seems relevant here, http://eugenioz.blogspot.com/2013/07/php-mssql-nvarchar-fetch-and-write-utf.html.

In case that site removes the post or goes down the solution is to cast the nvarchar as a varchar.

SELECT CAST(CAST([field] AS VARCHAR(8000)) AS TEXT) AS field FROM table

For insertion it is showing it as

INSERT INTO some_table (some_nvarchar_field)  VALUES(CONVERT(nvarchar(MAX), 0x'.$value.'))
chris85
  • 23,846
  • 7
  • 34
  • 51