generate BLOB data to XML

I am trying to generate BLOB data(GIF image from MySQL) using the following code. I am getting 'An invalid character was found in text content.'. Could you please let me know if there are any suggestions?

$connection = mysql_connect( $db_host, $db_username, $db_password );

$result = mysql_query("SELECT * from files");
header("Content-Type: application/xml");

echo sqlToXml($result, "entries", "entry");

    function sqlToXml($queryResult, $rootElementName, $childElementName) {
        $w = new XMLWriter();
        // use tabs as indents
        $w->setIndentString("   ");
        $w->startDocument("1.0", 'UTF-8');

        while($record = mysql_fetch_object($queryResult)) {
            for ($i = 0; $i < mysql_num_fields($queryResult); $i++) { 
                $fieldName = mysql_field_name($queryResult, $i); 
                if(!empty($record->$fieldName)) {
                else {
                $w->endElement(); // $fieldName

            $w->endElement(); // $childElementName
        $w->endElement(); // $rootElementName
        return $w->outputMemory();


Your inner loop's pretty verbose. Why not:

while($row = mysql_fetch_assoc($result)) {
   foreach($row as $key => $value) {

Also, note that empty() can be dangerous in cases like this, especially if your data can naturally contain things like integer 0 values. empty(0) is TRUE in PHP.

Need Your Help

(Play 2.4.2, Play Slick 1.0.0) How do I apply database Evolutions to a Slick managed database within a test?

playframework-2.4 play-slick

I would like to write database integration tests against a Play Slick managed database and apply and unapply Evolutions using the helper methods described in the Play documentation namely, Evolutions.

Same address, multiple shared_ptr counters, is it forbidden by C++ standard?

c++ c++11 shared-ptr language-lawyer

Suppose I have the need to do the following (This is just some imaginative code for discussion of the C++ standard, thus I won't discuss why I design it this way, so don't bother me with something ...