title: PDO fetches truncated XML from MS SQL database
body: <p>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.</p>
  <p>The problem is that retrieving the XML data results in the following error message:</p>
  <blockquote>
  <p>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)</p>
  </blockquote>
  <p>I'm type casting to retrieve the XML data, which is stored as text in the database. I don't necessarily <em>need</em> 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.</p>
  <p>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:</p>
  <blockquote>
  <p>Premature end of data in tag <em>ABC</em> line <em>123</em></p>
  <p>expected '&gt;'</p>
  </blockquote>
  <p>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:</p>
  <pre><code>SELECT CONVERT(VARCHAR(MAX), CAST(XML_DATA AS xml))
  </code></pre>
  <p>I'm then able to squeeze a few more characters out of the string - maxing out at a string length of 5085.</p>
  <p>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.</p>
  <p>How can I retrieve the XML data in its entirety? What's causing the cut-off? The PHP/PDO, or the MS SQL database?</p>
  <p>Any suggestions?</p>
  <p><strong>Additional information:</strong>
  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 <a href="https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_1_9/amzn-envelope.xsd" rel="nofollow noreferrer">Amazon MWS</a>.</p>