retrieving data from a db and output in xml

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

retrieving data from a db and output in xml

Post by ol4pr0 »

hi there...

i hope somebody can help me on this one.

I need to Generate a xml output code by reading the dbase.

how do i connect to the db and than have it displayed or rewritten to a .xml file ?

Also since i am only familiar with the mysql, is it possible for a vb program to connect to mysql?

many thanks for whom has the answer(s)

ol4pr0
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Here's a rough plan:

Code: Select all

<?php

$link = mysql_connect("localhost", "root"); // connect to mysql
$db = mysql_select_db("test"); // select db

$output = ''; // make output var

$query = "SELECT name, age, gender FROM people ORDER BY name LIMIT 5"; // query
$result = mysql_query($query, $link); // result

while($rows = mysql_fetch_array($result)) { // rows

// add to output
$output .= <<< XML

<person>
   <name>{$rows['name']}</name>
   <gender>{$rows['gender']}</gender>
   <age>{$rows['age']}</age>
<person>

XML;

}

// send header
header("Content-Type: text/xml");

// yes i copied and pasted from one of my old skripts
// output
echo <<< OUT
<?xml version="1.0" encoding="ISO-8859-1"?>

<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:hr="http://www.w3.org/2000/08/w3c-synd/#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/">

   <channel>
       <title>ChaosDreamers.com News and Updates</title>
       <description>ChaosDreamers.com - Blog, News, Articles, RSS/RDF Feed</description>
       <link>http://www.chaosdreamers.com</link>
   </channel>

   <channel>

$output

   </channel>

</rdf:RDF>
OUT;

?>
Hope it gives you an idea,

-Nay
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Thanks that surely gave me a new look on that subject

Post by ol4pr0 »

I had already figured something out by getting me a book from o reilly

but that code sure gave me a other way on coding it.


o. reilly said something like this.

$doc->create_element($table_id);
$occ = $root->append_child($occ);

by using the create_element and append_child.


dont know what i am going to use yet..

since i am now trying to get it to work with a SOAP. if not ill just use the DOM XML version :)

thanks alot NAY
Post Reply