4

I do the following in my php code :

$q="SELECT * FROM {$table} where x;
$link = mysqli_connect("localhost", "test", "test","mytable");
$res = mysqli_query($link,$q);
 if($res)
   {
       $row = mysqli_fetch_assoc($res);
       header("Content-type: text/xml");
       header("Content-Disposition: attachment; filename=$name");
       echo $row['blob'];
   }

I can see that the data(xml file) that I uploaded into mysql does not have any leading spaces but when I run the above code 3 new lines and a space appear and the file is not well formed xml any more. Any idea why the exact contents are not being read from the table?

11
  • Have you looked in the MySQL database to see if there are new line characters there, this will rule out the script as an issue. How is the XML not well formed anymore. Do you mean there are tags missing etc, or do you mean the browser no longer interprets the XML as XML. Or do you mean it isn't indented properly? Commented Sep 26, 2012 at 0:01
  • Store XML as text, blob's are for binary data. On that note, don't store XML.. Commented Sep 26, 2012 at 1:26
  • XML Parsing Error: XML or text declaration not at start of entity Line Number 3, Column 2: Commented Sep 26, 2012 at 1:27
  • which is supposed to be in the first line is on line 3 column 2 Commented Sep 26, 2012 at 1:41
  • @Chris I looked at the MySQL DB and there are no new lines there.It is funny how I get these new lines when I read them using php. Commented Sep 26, 2012 at 1:42

2 Answers 2

2

Figured it out.A silly mistake. My open php tag started on line 3 column 2

> <?php

and that made the 'echo' starting from the same line (line 3 column 2). Is that how echo is supposed to work?

Sign up to request clarification or add additional context in comments.

Comments

0

You should investigate where the extra newlines are coming from, but you could get around your problem by running:

trim($row['blob']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.