Using PHP to get MSSQL data - Error: "Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library"

I am trying to use a PHP webpage to get data from MSSQL and get the error message shown in the Question Title.

This is my connection code:

$hostname = "MAIN";
$username = "sa";
$password = "";
$dbName = "NewSQL";
MSSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO RESPOND.");
mssql_select_db($dbName) or DIE("Table unavailable");

$query = "SELECT * FROM Customer";
$result = mssql_query($query);      
$numrows = mssql_num_rows($result);

I have found out the problem is down to 2 NTEXT fields in the MSSQL table I am trying to select from. I have found this solution:

mssql_query("SELECT CAST(field1 AS TEXT) AS field1 FROM table;");

Which would solve it - but I want to do a 'SELECT *'.

Can anyone provide me with a better solution or a way of rewriting my currently located solution to 'SELECT *' and simultaneously select the 2 NTEXT fields 'AS TEXT'?

Thanks.
LVL 4
wbstechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wbstechAuthor Commented:
Sorry that was an idiotic question. I should have paid more attention to the similarities between MySQL and MSSQL.

The below line fixed it:

$query = "SELECT CusID, OperaRef, CoName, Name, Add1, Add2, Add3, City, PostCode, Tel, Fax, Mobile, Email, Custype, CAST(Notes AS Text) As Notes, SendMail, Status, CAST(Hyperlink AS Text) AS Hyperlink FROM Customer";
0
Anthony PerkinsCommented:
A better approach would be to change the column data type from ntext to text.  Unless, of course you are using double-byte characters such as chinese, in which case your select with CAST statement would fail, too.

>>The below line fixed it:<<
Please close the question.  See here:
I answered my question myself. What do I do?
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/help.jsp#hi70
0
GranModCommented:
Closed, 500 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.