[SOLVED] XML > MySQL?

This is a discussion on "[SOLVED] XML > MySQL?" within the PHP Forum section. This forum, and the thread "[SOLVED] XML > MySQL? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 5th, 2008, 01:59
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
[SOLVED] XML > MySQL?

I've learnt how to easily handle XML with PHP now.
So which would be faster, a blog driven by parsing XML or querying a database?
I'm pretty sure it's the XML one right?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote

  #2 (permalink)  
Old Jan 5th, 2008, 02:07
Highly Reputable Member
Join Date: Sep 2007
Age: 15
Posts: 717
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: XML > MySQL?

That depends on how big you're expecting your blog to get. If you expect it to be huge, I'd go with the XML since it can store more data. However, MySQL is faster. Tough decision! Speed vs. size...
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)

Last edited by Stuart; Jan 5th, 2008 at 02:37.
Reply With Quote
  #3 (permalink)  
Old Jan 5th, 2008, 02:12
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: XML > MySQL?

I would say MySQL by far!

XML is working with files -- basically treated as text by PHP... MySQL is many times faster than PHP.. So adding the need for PHP to work with XML files would further slow things down..

I wouldn't depart from convention in this case because convention has it right -- use a database
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #4 (permalink)  
Old Jan 5th, 2008, 02:18
Highly Reputable Member
Join Date: Sep 2007
Age: 15
Posts: 717
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: XML > MySQL?

Yeah, good point. Since it's a blog, text is all he needs to store. But when you add more data, XML becomes slow. However, a MySQL database is hard to manage when you put a lot of data into it, unless you have really good shell software
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Reply With Quote
  #5 (permalink)  
Old Jan 5th, 2008, 02:21
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: XML > MySQL?

Cheers Luke
Two questions though.
1.) What are the best uses for XML storage?

2.) This is my XML:
HTML: Select all
<?xml version="1.0" encoding="utf-8"?>
<numbers>
    <no>1</no>
    <no>2</no>
    <no>3</no>
</numbers>
And my PHP parsing:
PHP: Select all

define('XML''numbers.xml');
$xml = new SimpleXMLElement(XMLNULLtrue);

for(
$i 4$i 200$i++) {
$xml->addChild('no'$i);
}

foreach(
$xml as $n) {
echo 
$n.'<br';


I would expect this to list 1 to 200(abouts) seperated by <br>s but it just print: 1
Without the addChild() loop, it list 1-3.
What am i doing wrong?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #6 (permalink)  
Old Jan 5th, 2008, 02:22
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: XML > MySQL?

Quote:
Originally Posted by swagner View Post
. But when you add more data, XML becomes slow.
Obviously but XML can handle larger data better than MySQL.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #7 (permalink)  
Old Jan 5th, 2008, 02:24
Highly Reputable Member
Join Date: Sep 2007
Age: 15
Posts: 717
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: XML > MySQL?

Yes, I know. That's why I originally suggested XML. Luke mentioned that MySQL is faster, and that is also true. So, it really depends...
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Reply With Quote
  #8 (permalink)  
Old Jan 5th, 2008, 02:27
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: XML > MySQL?

how many times did you just contradict yourself? o_0
"a string like this long do do do doododododododododoododododododododoodo
times about 50 times would go into mysql and 500 times this length into XML"
Agree?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #9 (permalink)  
Old Jan 5th, 2008, 02:36
Highly Reputable Member
Join Date: Sep 2007
Age: 15
Posts: 717
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: XML > MySQL?

Yes, XML is better for storage, but MySQL is faster! Read my first post!
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Reply With Quote
  #10 (permalink)  
Old Jan 5th, 2008, 02:45
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: XML > MySQL?

Quote:
Yeah, good point. Since it's a blog, text is all he needs to store. But when you add more data, XML becomes slow. However, a MySQL database is hard to manage when you put a lot of data into it, unless you have really good shell software
Relational databases are as good as their design.. If you don't plan your database it will fall apart when data is increased. A well designed database is easy to manage and can contain arbitrary amounts of data. I would never even consider using files over a database if a database was available.


@Alex
You need to rewrite your code a little

PHP: Select all

define('XML''numbers.xml');

$xml = new SimpleXMLElement(XMLNULLtrue);
$numbers $xml->addChild('numbers');
for(
$i 4$i 200$i++) {
$numbers->addChild('no'$i);
}
foreach(
$numbers as $n) {echo $n.'<br';} 
You need to add the whle structure -- the way you were doing it, it is just adding <no> elements to the root structure and not withing <numbers>
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #11 (permalink)  
Old Jan 5th, 2008, 10:12
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: XML > MySQL?

Thanks Luke but that just outputs "4".
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #12 (permalink)  
Old Jan 5th, 2008, 10:17
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: XML > MySQL?

It generates this XML:
HTML: Select all
<?xml version="1.0" encoding="utf-8"?>
<numbers>
  <no>1</no>
  <no>2</no>
  <no>3</no>
  <numbers>
    <no>4</no>
    <no>5</no>
    <no>6</no>
    <no>7</no>
    <no>8</no>
    <no>x</no> 
....
edit!

This code generates the right XML but I still can't get it to loop through.
PHP: Select all

<?php 

define
('XML''numbers.xml');

$xml = new SimpleXMLElement(XMLNULLtrue);

$numbers $xml;

for(
$i 4$i 200$i++) {

$numbers->addChild('no'$i);

}

foreach(
$xml as $n) {echo $n.'<br';} 
$xml->asXML(XML);
 
?>
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)

Last edited by alexgeek; Jan 5th, 2008 at 10:21.
Reply With Quote
  #13 (permalink)  
Old Jan 5th, 2008, 10:25
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: XML > MySQL?

Okay I didn't so that quite right I don't think..

PHP: Select all

define('XML''numbers.xml');

$xml = new SimpleXMLElement(XMLNULLtrue);
$numbers $xml->children();
$numbers $numbers[0]
for(
$i 4$i 200$i++) {
$numbers->addChild('no'$i);
}
foreach(
$numbers as $n) {echo $n.'<br';} 
I forgot to grab the reference to numbers -- I was adding one previously... This meant there were two lots of numbers.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #14 (permalink)  
Old Jan 5th, 2008, 10:45
alexgeek's Avatar
Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,771
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: XML > MySQL?

Thanks Luke, that was almost right just needed to alter the $numbers variable.
I think you were referencing to a lower level when you were actually on it.
$xml when defined holds <numbers>, and I think you were trying to access numbers like: $xml->numbers - which doesn't exist.

Anyway this code works perfectly. Thanks (thread solved)
PHP: Select all

define('XML''numbers.xml');

$xml = new SimpleXMLElement(XMLNULLtrue);

$numbers $xml;

$numbers $numbers[0];

for(
$i 4$i 200$i++) {

$numbers->addChild('no'$i);

}

foreach(
$numbers as $n) {echo $n.'<br>'; }
$xml->asXML(XML
HTML: Select all
<?xml version="1.0" encoding="utf-8"?>
<numbers>
  <no>1</no>
  <no>2</no>
  <no>3</no>
  <no>4</no>
  <no>X</no>
</numbers>
P.S. I'm going to create a settings API, allowing an easy way to set, retrieve and edit settings that get stored in XML file.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] do I need mysql set up on my computer? Oak Databases 7 Jan 18th, 2008 14:27
[SOLVED] mysql question longstand Databases 5 Oct 23rd, 2007 04:11
[SOLVED] Connecting/Using MySQL and ASP Monie Classic ASP 8 Oct 12th, 2007 09:00
[SOLVED] MySQL to MSSQL Anonymous User Databases 7 Oct 6th, 2003 07:48


All times are GMT. The time now is 22:04.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43