Neeraj
Neeraj

Reputation: 9175

PDO not reading nvarchar datatye of MSSQL Server

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.

Upvotes: 3

Views: 2114

Answers (1)

chris85
chris85

Reputation: 23880

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

Upvotes: 3

Related Questions