473,225 Members | 1,158 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,225 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 18454
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
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.