ok I found my one way .. I did it with FILES via php: this is the code if anyone needs help to that:

<?php
include "connection.php";
$myFile = "rss.xml";
$fh = fopen($myFile, 'w') or die("can't open file");

$rss_txt .= '<?xml version="1.0" encoding="utf-8"?>';
$rss_txt .= "<rss version='2.0'>";
$rss_txt .= '<channel>';
    $query = mysql_query("SELECT * FROM rssfeeds");
    while($values_query = mysql_fetch_assoc($query))
    {
        $rss_txt .= '<item>';

        $rss_txt .= '<title>' .$values_query['title']. '</title>';
        $rss_txt .= '<link>' .$values_query['link']. '</link>';
        $rss_txt .= '<description>' .$values_query['summary']. '</description>';

        $rss_txt .= '</item>';
    }
$rss_txt .= '</channel>';
$rss_txt .= '</rss>';

fwrite(rss_txt);
fclose($fh);
?>
Answer from Kiriakos Grhgoriadhs on Stack Overflow
๐ŸŒ
Plus2Net
plus2net.com โ€บ php_tutorial โ€บ file-xml.php
Generating xml file by reading data from MySQL table in PHP
<?Php require "config.php"; // Connect to database ////////////////////////////////////// $sql="SELECT * FROM student"; $str ="<?xml version='1.0' encoding='UTF-8'?>n<student>"; foreach ($dbo->query($sql) as $row) { $str .= "\n<details>\n\t\t\t<id>$row[id]</id>\n\t\t\t<name>$row[name]</name> "; $str .= "\n\t\t\t <class>$row[class]</class>\n</details>"; } $str.= "\n</student>"; //$str=nl2br($str); //echo htmlspecialchars($str); // remove this line if you are writing to file echo $str; /// Write to file //////////// $file_name="test_file.xml"; // file name $fp = fopen ($file_name, "w"); // Open
๐ŸŒ
Codefixup
codefixup.com โ€บ create-and-save-xml-file-using-mysql-data-in-php
How to Generate XML file Dynamically in PHP and Mysql โ€“ PHP Programming Blog | CodeFixUp.com
Step 1: Declare the header content type as text/xml ยท header(โ€˜Content-Type: text/xml; charset=utf-8โ€™); Step 2: Make an Database connection. Step 3: Write the xml code to generate xml data.
๐ŸŒ
Source Code Tester
sourcecodester.com โ€บ how-create-xml-file-mysql-database-using-phpmysqli.html
How to Create XML file from MySQL Database using PHP/MySQLi | SourceCodester
Lastly, we create our script that creates XML file from our MySQL Database. Create a new file named create_xml.php and paste the below codes.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 5313258 โ€บ using-php-to-create-an-xml-file-from-a-mysql-db
using php to create an xml file from a mysql db - Stack Overflow
... The code above is exactly the same code as i hav except i left out the closing tag at the end in the code above.theres no ? before the > in the line $root = $doc->createElement('root'); ... Set the content type to be XML, so that the browser ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ how-to-generate-an-xml-file-dynamically-using-php
How to generate an XML file dynamically using PHP? - GeeksforGeeks
July 26, 2024 - <?php $con=mysqli_connect("localhost", "root", "", "fitness"); if(!$con){ echo "DB not Connected..."; } else{ $result=mysqli_query($con, "Select * from users"); if($result>0){ $xml = new DOMDocument("1.0"); // It will format the output in xml format otherwise // the output will be in a single row $xml->formatOutput=true; $fitness=$xml->createElement("users"); $xml->appendChild($fitness); while($row=mysqli_fetch_array($result)){ $user=$xml->createElement("user"); $fitness->appendChild($user); $uid=$xml->createElement("uid", $row['uid']); $user->appendChild($uid); $uname=$xml->createElement("una
๐ŸŒ
Write
write.corbpie.com โ€บ generating-and-creating-an-xml-file-from-mysql-with-php
Generating and creating an XML file from MySQL with PHP
May 7, 2021 - $xml = new SimpleXMLElement('<objects/>'); $select = $db->query("SELECT `type`, `name`, `value`, `enabled` FROM `xml_data`;"); while ($row = $select->fetch(PDO::FETCH_ASSOC)) { ($row['type'] === 'category') ? $obj = $xml->addChild('category') ...
Find elsewhere
๐ŸŒ
E-learning Spot
learningspot.altervista.org โ€บ php-generate-xml-files-database
PHP generate XML files from database | E-learning Spot
December 2, 2017 - $user = 'root'; $password = 'root'; $db = 'test'; $host = 'localhost'; $port = 8889; $conn = new PDO("mysql:host=$host; dbname=$db; port=$port", $user, $password); Now that we have access to the database, we can perform our queries and convert ...
๐ŸŒ
Kirupa
kirupa.com โ€บ web โ€บ mysql_xml_php.htm
kirupa.com - Output mySQL data as XML with PHP
Take data from a mySQL database and process it into XML for use later.
๐ŸŒ
YouTube
youtube.com โ€บ programmer blog
How to generate xml files using php and mysql | PHP Tutorial Series | Programmer Blog - YouTube
In this tutorial, we are going to learn how to generate XML using php & MySQL. PHP provide a DOMDocument class. DOMDocument is used to create XML documents...
Published ย  February 5, 2022
Views ย  5K
๐ŸŒ
PHP Classes
phpclasses.org โ€บ package โ€บ 2560-PHP-Generate-XML-document-from-a-MySQL-database-data.html
MySQL to XML: Generate XML document from a MySQL database data - PHP Classes
This class can be used to generate XML documents from data of a given MySQL database. It can either dump the data of the results of a given SQL query, or dump the all the data of all database tables. The XML documents are generated using the PHP DOM XML extension .
Top answer
1 of 8
390

I'd use SimpleXMLElement.

<?php

$xml = new SimpleXMLElement('<xml/>');

for ($i = 1; $i <= 8; ++$i) {
    $track = $xml->addChild('track');
    $track->addChild('path', "song$i.mp3");
    $track->addChild('title', "Track $i - Track Title");
}

Header('Content-type: text/xml');
print($xml->asXML());

?>

$xml->asXML() can also take a filename as a parameter to save to that file

2 of 8
191

To create an XMLdocument in PHP you should instance a DOMDocument class, create child nodes and append these nodes in the correct branch of the document tree.

For reference you can read https://www.php.net/manual/en/book.dom.php

Now we will take a quick tour of the code below.

  • at line 2 we create an empty xml document (just specify xml version (1.0) and encoding (utf8))
  • now we need to populate the xml tree:
    • We have to create an xmlnode (line 5)
    • and we have to append this in the correct position. We are creating the root so we append this directly to the domdocument.
    • Note create element append the element to the node and return the node inserted, we save this reference to append the track nodes to the root node (incidentally called xml).

These are the basics, you can create and append a node in just a line (13th, for example), you can do a lot of other things with the dom api. It is up to you.

<?php    
    /* create a dom document with encoding utf8 */
    $domtree = new DOMDocument('1.0', 'UTF-8');

    /* create the root element of the xml tree */
    $xmlRoot = $domtree->createElement("xml");
    /* append it to the document created */
    $xmlRoot = $domtree->appendChild($xmlRoot);



    /* you should enclose the following lines in a loop */
    $currentTrack = $domtree->createElement("track");
    $currentTrack = $xmlRoot->appendChild($currentTrack);
    $currentTrack->appendChild($domtree->createElement('path','song1.mp3'));
    $currentTrack->appendChild($domtree->createElement('title','title of song1.mp3'));

    $currentTrack = $domtree->createElement("track");
    $currentTrack = $xmlRoot->appendChild($currentTrack);
    $currentTrack->appendChild($domtree->createElement('path','song2.mp3'));
    $currentTrack->appendChild($domtree->createElement('title','title of song2.mp3'));

    /* get the xml printed */
    echo $domtree->saveXML();
?>

Edit: Just one other hint: The main advantage of using an xmldocument (the dom document one or the simplexml one) instead of printing the xml,is that the xmltree is searchable with xpath query

๐ŸŒ
Chron.com
smallbusiness.chron.com โ€บ use-php-mysql-xml-27822.html
How to Use PHP for MySQL to XML
November 22, 2017 - Add the XML header information at the top of the PHP code file. The XML header information tells the user's browser that it needs to render XML data to the reader:header("Content-type: text/xml"); Create the MySQL connection and retrieve the ...
๐ŸŒ
Tonymarston
tonymarston.net โ€บ php-mysql โ€บ dom.html
Using PHP 5's DOM functions to create XML files from SQL data
August 22, 2004 - The following code will take the contents of $dbresult (any number of rows, each of which contains a series of name=value pairs) and write it to a variable as an XML string. This can subsequently be written to a disk file or transformed into an HTML document using the XSL functions which are ...
Top answer
1 of 4
2

I struggle a lot to find out this solution in mysqli format but nowhere i found the solution. Below is the solution i figured. Run this demo and map it your requirement, surely it will help.

<?php
//Create file name to save
$filename = "export_xml_".date("Y-m-d_H-i",time()).".xml";

$mysql = new Mysqli('server', 'user', 'pass', 'database');
if ($mysql->connect_errno) {
    throw new Exception(sprintf("Mysqli: (%d): %s", $mysql->connect_errno, $mysql->connect_error));
}

//Extract data to export to XML
$sqlQuery = 'SELECT * FROM t1';
if (!$result = $mysql->query($sqlQuery)) {
    throw new Exception(sprintf('Mysqli: (%d): %s', $mysql->errno, $mysql->error));
}

//Create new document 
$dom = new DOMDocument;
$dom->preserveWhiteSpace = FALSE;

//add table in document 
$table = $dom->appendChild($dom->createElement('table'));

//add row in document 
foreach($result as $row) {
    $data = $dom->createElement('row');
    $table->appendChild($data);

    //add column in document 
    foreach($row as $name => $value) {

        $col = $dom->createElement('column', $value);
        $data->appendChild($col);
        $colattribute = $dom->createAttribute('name');
        // Value for the created attribute
        $colattribute->value = $name;
        $col->appendChild($colattribute);           
    }
}

/*
** insert more nodes
*/

$dom->formatOutput = true; // set the formatOutput attribute of domDocument to true 
// save XML as string or file 
$test1 = $dom->saveXML(); // put string in test1
$dom->save($filename); // save as file
$dom->save('xml/'.$filename);   
?>
2 of 4
1

If you have access to the mysql CLI, here's my quick hack for achieving this:

$sql = "SELECT * FROM dockcomm WHERE listname = 'roortoor' 
and status IN ('P','E') and comm_type IN ('W','O') 
and comm_period NOT IN ('1','2','3','4') order by comment_num";

$cmd = "/usr/bin/mysql -u<person> -h<host>  -p<password> <database> --xml -e \"$sql\";";
$res = system($cmd ,$resval);
echo $res;
๐ŸŒ
Tonymarston
tonymarston.net โ€บ php-mysql โ€บ domxml.html
Using PHP 4's DOM XML functions to create XML files from SQL data
The following code will take the contents of $dbresult (any number of rows, each of which contains a series of name=value pairs) and write it to a variable as an XML string. This can subsequently be written to a disk file or transformed into an HTML document using the Sablotron XSLT processor ...
๐ŸŒ
EduTech Wiki
edutechwiki.unige.ch โ€บ en โ€บ PHP_-_MySQL_-_XML_tutorial_-_basics
PHP - MySQL - XML tutorial - basics - EduTech Wiki
Instead of reading an XML file we have to take an XML string as input. Code below is not tested but its intent must be ok, read the DOMDocument::loadXML entry of the PHP5 manual .... <?php error_reporting(E_ALL); // Substitute the code from the database example above, // e.g. retrieve the data from mysql and generate an XML string $XML = "<result> .....