I'm writing a web interface to MySQL that executes a couple queries and returns some XML data with the results of the queries. Right now, the table the query is running on has three LONGBLOB columns (for storing image data and the like).
However, when I try to parse the XML, I run into trouble with certain characters in the BLOB columns: it looks like MySQL is just dumping the straight hex data into the stream, which is not being accepted by my parser.
Is there a way I can have MySQL output well-formed XML that contains hex data? I looked at the mysqldump --hex-blob
option, but I'm working with the mysql
program since I need to run queries on tables, not just get the entire table's contents. I'd be OK with a string representation, an xs:hexBinary
element in the <field>
tag, or anything similar.
Edit: I'm working in PHP 5.2.9. The background of the question is to provide a sort of Digg-like API with multiple HTTP-accessible endpoints, e.g. /objects
, /edit
, and so forth. The idea is that a number of client applications across multiple platforms can use the API as a common ground to access the same dataset without having to care about the database backing it (which is subject to change).
One of the object types I'm storing is a (small) image, and I'd like to do so directly in the database using the MySQL LONGBLOB type. (I'm only responsible for making the API work with the MySQL backend database, so answers can take the DB type, language, and utilities as givens.) Basically what I'm looking to do is find a way to provide the image back to the requesting application within the same XML document as some other mixed-type data (mostly strings).
Edit: I'm getting the XML out of MySQL using a combination of the mysql --xml
command-line program and the PHP passthru
function. This was the easiest way to get done what I wanted at the time I was developing it; is there a better way? Should I be building XML in PHP from the MySQL fields rather than depending on MySQL to do it for me? And if so, would that make sending image data in the XML easier?