ODBC query on MS SQL Server returning first 255 characters only in PHP PDO (FreeTDS)

后端 未结 4 2007
长发绾君心
长发绾君心 2020-12-19 09:33

I\'m currently trying to pull some data from a SQL Server database view that we have restricted access to from our Linux web server.

We don\'t need to edit the data

4条回答
  •  感动是毒
    2020-12-19 10:10

    One more factoid for this issue. As of 2015, returning a value of type XML results in the first 256 characters being returned cleanly. However, most of the rest of the XML will be returned as apparently random garbage, with an occasional clear fragment of text. In fact, if I had to guess, the query returns a random block of memory for all characters after 256.

    In my specific case, I was generating XML (using multiple FOR XML nested queries) to send to a website for display. In this case, the solution I found was to use the CAST hack, casting the data to varchar(max).

    So remember: If you see a block of 256 clear characters followed by random garbage in your query results, it is probably an XML value being returned as an XML type instead of a varchar(max) type.

    CAVEAT: This may only apply if the XML is dynamically generated.

提交回复
热议问题