I'm attempting to write a PHP script which will use PDO to retrieve XML data stored in an MS SQL database, then parse the XML data using SimpleXML.
The problem is that retrieving the XML data results in the following error message:
SQLSTATE[HY000]: General error: 10007 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. [10007] (severity 5)
I'm type casting to retrieve the XML data, which is stored as text in the database. I don't necessarily need to have this returned as real XML. Retrieving it as a string will be fine, since I'm using SimpleXML to parse the data anyway.
However- if I attempt to retrieve this data as text, without type casting, the string of XML is always cut short. Then SimpleXML spits out a long list of errors like:
Premature end of data in tag ABC line 123
expected '>'
The the string length of the returned XML maxed out at 4999. If I type cast the data to XML, then convert to VARCHAR, like so:
SELECT CONVERT(VARCHAR(MAX), CAST(XML_DATA AS xml))
I'm then able to squeeze a few more characters out of the string - maxing out at a string length of 5085.
The casting and converting was just a wild guess. The only thing that it has proven is that I don't know where these max lengths are coming from, or what they mean.
How can I retrieve the XML data in its entirety? What's causing the cut-off? The PHP/PDO, or the MS SQL database?
Any suggestions?
Additional information: The database is read-only. The server is running PHP Version 5.2.17. The following PDO drivers are installed: sqlite, sqlsrv, mssql, mysql, odbc; PDO Driver for MSSQL DB-lib: MSSQL_70. The XML is from Amazon MWS.