Well, here's my little contribution.
Use when your XML file looks like this:
<database>
<tablename>
<id>1</id>
<name>George</name>
<type>fish</type>
</tablename>
<tablename>
<id>3</id>
<name>Renee</name>
<type>apple</type>
</tablename>
</database>
Here's a start to your script to load your table back in:
$table = simplexml_load_file("backup.xml");
foreach( $table->children() as $entry )
{
$query1 = "INSERT INTO mytable ( ";
$query2 = " ) VALUES( ";
foreach( $entry->children() as $info )
{
$query1 .= $info->getName() . ", ";
$query2 .= "\"" . addslashes($info) . "\", ";
}
// kill trailing commas and form into full query
$query = substr( $query1, 0, -2 ) . substr( $query2, 0, -2 ) . " )";
mysql_query( $query ) or die( mysql_error() );
}
Notes
- I used PHP's SimpleXML. You need to be using PHP 5 for this to work.
- This only imports one table.
- Probably not the most memory efficient; for very large XML files this will probably time out.
- I started writing this post and never completed it, but I saw it again today (7/19/09) and figured I might as well post... I've still got a thing or two to learn about prompt documentation.
Nagisa, you really need to teach me PHP, so I can actually understand what the heck is going on there. <.>
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHey, its been a little while since I caught up on your blog (or added to my own for that matter). Anyway, I was curious how long did it take you to learn PHP? I feel like an idiot because I haven't learned PHP but need to, hows that for procrastination?
ReplyDeleteBy the way, what happened to nuggit.nu?
Thank you for the link building list.I am going jot down this because it will help me a lot.Great blog! Please keep on posting such blog.
ReplyDeleteprivate label website builder