shadowayex Posted April 29, 2009 Share Posted April 29, 2009 So, I've been reading up on XML and I found that PHP can read data from and write data to XML files, as far as I understand. If this is true, would it be possible to replace a MySQL database with XML files instead.Like, instead of having a user table in a database that had the fields id, username, and password, could I use an XML file that looked like: <?xml version="1.0"?><users> <user> <id>1</id> <username>shadowcat678</username> <password>1337P455W0RD</password> </user> <user> <id>2</id> <username>batman111</username> <password>alskdjfh</password> </user> and so on....</users> Would that work? Given I built the PHP parser correctly.And if so, would it be recommended? Link to comment Share on other sites More sharing options...
jeffman Posted April 29, 2009 Share Posted April 29, 2009 That is exactly the point of XML. And the PHP interface already exists: http://www.php.net/manual/en/refs.xml.phpAnd of course you can use AJAX to grab XML directly into Javascript and manipulate it with all the DOM functions you already know.There are speed issues, both client-side and server-side. I think Chrome may be pushing the envelope speed-wise on the client side. At least, that's their big selling point: 20x faster javascript engine, or some such.boen_robot is really the guy to answer this. Maybe Synook? Wait for their hemispheres to wake up. I'm just making conversation. Link to comment Share on other sites More sharing options...
shadowayex Posted April 29, 2009 Author Share Posted April 29, 2009 I would really like to use XML rather than databases, way more portable, and if it's the better route to go, I'll do it. I'm starting to fall in love with XML . Link to comment Share on other sites More sharing options...
Ingolme Posted April 29, 2009 Share Posted April 29, 2009 While you can store information in XML as a database, it has some inconvenients.It is more difficult to query. When you want to retrieve information in this manner "SELECT * FROM table WHERE number>5" from an XML file, you'll find that you have to do many loops to find all the <table> elements that have a child node <number> with a value greater than 5 in it. There also is the "ORDER BY" which is really hard to implement in XML.Forgetting about querying, the second problem with XML databases is speed. XML files take more space than other database formats. But even if it didn't, the problem is that PHP has to load the entire file (which may have thousands of rows) to perform a query, even if it is just to retrieve two rows.Rather than for a database, I find XML more useful for storing more static data that isn't read and changed as often, like a list of texts in different languages to display on a certain page. Link to comment Share on other sites More sharing options...
shadowayex Posted April 29, 2009 Author Share Posted April 29, 2009 Ok, I see. So if I'm just loading something simple, like maybe some statistics or something, XML files would be nice because it'll be a relatively small amount of data that's probably not going to change. But if it's something that requires many queries and needs to be reordered and whatnot, I should use databases, correct? Link to comment Share on other sites More sharing options...
Ingolme Posted April 29, 2009 Share Posted April 29, 2009 Ok, I see. So if I'm just loading something simple, like maybe some statistics or something, XML files would be nice because it'll be a relatively small amount of data that's probably not going to change. But if it's something that requires many queries and needs to be reordered and whatnot, I should use databases, correct?Generally yes. But it can often be subjective. Link to comment Share on other sites More sharing options...
boen_robot Posted April 29, 2009 Share Posted April 29, 2009 Ok, I see. So if I'm just loading something simple, like maybe some statistics or something, XML files would be nice because it'll be a relatively small amount of data that's probably not going to change. But if it's something that requires many queries and needs to be reordered and whatnot, I should use databases, correct?I completely agree with Ingolme (it's like he was in my mind and did a copy&paste ), and I use exactly this kind of combo. In addition to using XML for static files, you may (at a later point though...) find it useful to store "configuration" data in it alongside the XHTML* or whatever kind of "small amoung of data" you have. If the XML file is being processed by PHP anyway, this is a feasable thing to do. If it's on the client side, I'd use a separate, dynamically generated XML file (I've never been able to see the use case of a static XML, processed by the client, when the server also has PHP support).* I have a general rule to use an existing vocablulary if one exists for the purpose of what I'm doing. Since most "static" data is generally going to be inserted into XHTML, it's perfectly fine to store the original data in XHTML also. It would also ease the transformation process, if one is needed at all. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.