Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7594533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:26:25+00:00 2026-05-30T21:26:25+00:00

I currently have a script written in PHP where I connect to a database

  • 0

I currently have a script written in PHP where I connect to a database in phpMyAdmin, and then parse all of the table values into an XML document.

Here is how the script works:

    $xmlBody .= "<XML>";
$sql_news = mysql_query("SELECT * FROM news_table");

$xmlBody .= "<News_Table>";

//this while loop churns out the values of our "news_table" table
while($row_news = mysql_fetch_array($sql_news)){
    // Set DB variables into local variables for easier use 
    $id_news = $row_news["news_id"];
    $author_news = $row_news["news_author"];
    $time_news = $row_news["news_time"];
    $title_news = $row_news["news_title"];
    $content_news = $row_news["news_content"];
    $desc_news = $row_news["news_description"];
    $image_news = $row_news["news_image"];

    $xmlBody .= '
<News_Table_Entry> 
    <DataID>' . $id_news . '</DataID> 
    <DataAuthor>' . $author_news . '</DataAuthor>
    <DataTime>' . $time_news . '</DataTime>
    <DataTitle>' . $title_news . '</DataTitle>
    <DataContent>' . $content_news . '</DataContent> 
    <DataDesc>' . $desc_news . '</DataDesc>
    <DataImage>' . $image_news . '</DataImage>
</News_Table_Entry>';
} // End while loop

$xmlBody .= "</News_Table>";

mysql_close(); // close the mysql database connection
$xmlBody .= "</XML>";
echo $xmlBody; 
?>

How do I create and output this as an external XML file? I’ve successfully got this script working, but using all of the methods for writing out to XML isn’t working. Using the

echo 'Wrote: ' . $doc->save("/tmp/test.xml") . ' bytes'; // Wrote: 72 bytes

Function isn’t working, along with the fwrite function as well. I’ve been working at trying to figure this out for a few days, but none of the solutions I’ve been told to try out have worked. Any help or insight would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:26:27+00:00Added an answer on May 30, 2026 at 9:26 pm

    According to your code, you’re already building the XML content yourself. XML files are just regular text files, so in this case you don’t need any of the special XML functions that validate and render. Instead, you can simply save your text to the .xml file:

    file_put_contents('/tmp/test.xml', $xmlBody);
    

    file_put_contents allows you to forego all the fopen/fwrite functions, so it’s the easiest way to write content to disk.


    On the other hand, if you do want to learn to build a structured XML document with all the bells and whistles of consistency, look up SimpleXML or XMLWriter. A little more overhead that way, but doing all the markup by hand can be unwieldy, especially when one typo can invalidate your whole document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a PHP script to pull a query from an Oracle database
I have written a Python script that currently is designed to handle traditional CGI
I have written a PHP script which allows me to modify and update a
I have written a script image.php that is quite long, but I've just copied
I'm using emacs and I have written a script which uses current-buffer. However the
I currently have a script that scrapes proxies off websites, but I'm just wondering
I currently have a script which allows me to output the list of files
Currently I have a bash script which runs the find command, like so: find
I have a SQL script that inserts data (via INSERT statements currently numbering in
I have a batch script that calls a process and currently it waits for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.