Google Answers Logo
View Question
 
Q: Parsing a mySQL database ( No Answer,   1 Comment )
Question  
Subject: Parsing a mySQL database
Category: Computers > Programming
Asked by: jmo88-ga
List Price: $5.00
Posted: 28 Jul 2004 16:17 PDT
Expires: 27 Aug 2004 16:17 PDT
Question ID: 380500
I have a mySQL database that I want to extract information from and
port it to a particular software. For that end software, I have an XML DTD,
that defines how data should be formatted in order to import it.

My question is, what is the best programming language (which would you
recommend) to parse a MySQL DB, and convert the information to an XML
format as defined by the DTD? OR, can I just use MySQL to output
information from a DB to a format that I've defined???

****************Here's more details*******************
Here's an example of a portion of what I want to do:
the database has a table called 'router.' Each router in the table
will be identified by its 'name.'

For the software I'm using, I need an XML (text) file that has a line
for each router that looks like this:
<node name="router1" type="router"> <other info...> </node>
<node name="router2" type="router"> <other info...> </node>

Request for Question Clarification by palitoy-ga on 01 Aug 2004 10:00 PDT
Hello Jmo88

Do you still need any help on this question or has crythias-ga
answered it sufficiently for you?
Answer  
There is no answer at this time.

Comments  
Subject: Re: Parsing a mySQL database
From: crythias-ga on 28 Jul 2004 18:23 PDT
 
I'd say PHP :) It's built very well to handle things like this. 

The steps are essentially open the database, query the table, output
the information.

<? php
$host="localhost";
$user="username";
$password="sekrit";
$db="routerdb";
$link = mysql_connect($host,$user,$pwd) or die("Could not connect to Host.");
mysql_select_db($db) or die("Could not select database.");
$query="SELECT name, info, otherfield FROM table";
$result = mysql_query($query) or die("Could not run query." . mysql_error());
while ($answer = mysql_fetch_object($result)) {
  echo "<node name=\"" . $answer->name . "\" type=\"router\"><" .
$answer->info  . "> </node>\n";
}
?>

Redirect ourput to your file.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy