473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

from xml to mysql

with phpmyadmin i export a table of a mysql db in xml file. Now i want
import a xml file in a mysql db.
How can i do??
Thanks
Andrea
Jul 17 '05 #1
6 18462
Muppy wrote:
with phpmyadmin i export a table of a mysql db in xml file. Now i want
import a xml file in a mysql db.
How can i do??
Thanks
Andrea


I don't know phpmyadmin, but if it has a export to xml, does it not
have a import from xml to go along?

If it doesn't make your own :)
I don't know what your xml data looks like, but it's very
easy to transform

<sqldata>
<record>
<name>Pedro</name>
<eyecolor>brown</eyecolor>
</record>
<record>
<name>Muppy</name>
<eyecolor>blue</eyecolor>
</record>
<!-- ... ... ... -->
</sqldata>

into

insert into table (name, eyecolor) values ('Pedro', 'brown');
insert into table (name, eyecolor) values ('Muppy', 'blue');

and then mysql_query every one of the insert statments.
Happy Coding :-)
--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #2
> I don't know phpmyadmin, but if it has a export to xml, does it not
have a import from xml to go along?
no, it doesn't have.
If it doesn't make your own :)
I don't know what your xml data looks like, but it's very
easy to transform


It's not esay for me ;)
Any help will be appreciated
Thanks
Andrea

Jul 17 '05 #3
Muppy wrote:
It's not esay for me ;)
Any help will be appreciated


Ever tried regexps?

Take that data

<?php
$data = "<?xml version=\"1.0\"?>
<sqldata>
<record><name>Pedro</name><eyecolor>brown</eyecolor></record>
<record><name>Muppy</name><eyecolor>blue</eyecolor></record>
</sqldata>";
?>

and get all the records into an array

<?php
preg_match_all('#<record>(.*)</record>#Us', $data, $records);
?>

then, for each record, get the respective values, and insert into sql
I am treating all values as strings (quoting them with ')
you might want to test the column names and do it differently

<?php
foreach ($records[1] as $record) {
preg_match_all('#<(.*)>(.*)</\1>#Us', $record, $values);
// $values[1] has the column names
// $values[2] has the values to insert
$sql = "insert into table ("
. implode(', ', $values[1])
. ") values ('"
. implode("', '", $values[2])
. "')";
echo $sql, '<br />'; ### or mysql_query($sql)
}
?>
Happy Coding :-)
check the regexp page at php.net
** http://www.php.net/manual/en/ref.pcre.php

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #4
> Ever tried regexps?

no ;(
Many thanks for the help!
Andrea
Jul 17 '05 #5
On 4 Oct 2003 18:10:28 GMT, Pedro <he****@hotpop.com> wrote:
Muppy wrote:
It's not esay for me ;)
Any help will be appreciated


Ever tried regexps?


You can't parse XML fully with just regexps. Use an XML parser:
http://www.php.net/manual/en/ref.xml.php

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #6
Muppy wrote on Saturday 04 October 2003 12:24:
Ever tried regexps?


no ;(
Many thanks for the help!
Andrea


Either use XML parser in PHP per Andy's suggestion or use ActiveLink PHP XML
Package to manipulate XML (no PHP XML libs required):

http://www.active-link.com/intranet/software.php
http://php-xml.sourceforge.net/

Good luck!

--
Business Web Solutions
ActiveLink, LLC
www.active-link.com/intranet/
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nils Valentin | last post by:
Hi MySQL Fans ;-), Is it possible that the 3.08 series allows to connect to 4.0.14 versions but not to the 4.1 alpha-versions ? I get belows error when tryig to connect from DbVisualizer which...
0
by: amg | last post by:
--------------2ABCD8BC51CA575D47B206C8 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit --------------2ABCD8BC51CA575D47B206C8 Content-Type: text/plain;...
1
by: Khue Pham | last post by:
Does anyone knows how to copy database from one server to another. By copying I mean literally everything, not just the database. I know we can dump the database from one server then reload it to...
1
by: DD | last post by:
I have a mainform with a subform. The main form as a dropdown box "chooseDate", in the afterupdate event i requery the subform so all records with the same date are viewed. Now i only want to...
3
by: DD | last post by:
I have a mainform with a subform. > The main form has a dropdown box "chooseMonth", in the afterupdate event > i requery the subform so all records with the same date are viewed. > Now i only want...
3
by: eieiohh | last post by:
MySQL 3.23.49 PHP 4.3.8 Apache 2.0.51 Hi All! Newbie.. I had a CRM Open Source application installed and running. Windows Xp crashed. I was able to copy the contents of the entire hard...
1
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work....
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
0
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a...
7
by: Randy | last post by:
Folks: We have a web-based app that's _really_ slowing down because multiple clients are writing their own private data into a single, central database. I guess the previous programmer did...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.