I need to use xml as database in php. Till now i used mssql,mysql as database in php. Is it possible to do so?
-
Yes, it is possible. Inadvisable in many cases, but possible.George Cummins– George Cummins2011-08-18 14:55:34 +00:00Commented Aug 18, 2011 at 14:55
-
Why do you have to use xml?Mike– Mike2011-08-18 15:01:58 +00:00Commented Aug 18, 2011 at 15:01
-
A little more background would help us to help you better. There are e.g. database systems that can handle xml documents "natively" to varying extends, e.g. www-01.ibm.com/software/data/db2/express .VolkerK– VolkerK2011-08-18 15:24:01 +00:00Commented Aug 18, 2011 at 15:24
-
See Apache Xindice, it's a Native XML database server.netcoder– netcoder2011-08-18 15:30:56 +00:00Commented Aug 18, 2011 at 15:30
3 Answers
XML is not a database. It's simply a standardized method of marking up data. You can treat it as a database, but you don't want to. The overhead of maintaining an XML tree is massive, especially if you have a lot of data. XML is NOT efficient for fast/random/abitrary access, especially since you'd have to load/parse the whole XML tree for every "database query" you perform.
About the only thing you'd gain from this is portability, but whatever site you're building would run slower than Windows 7 on an abacus.
2 Comments
Of course it is, it depends how you want it laid out though.
Although, XML isn't technically a database.
If you were using a system that requires the use of user registration, you could have either an XML file per user, or an overall user XML file.
1 - User1.xml
<user>
<username>User</username>
<password>Pass</password>
</user>
2 - Users.xml
<user>
<username>User1</username>
<password>Pass</password>
</user>
<user>
<username>User2</username>
<password>Pass2</password>
</user>
These are some very simple methods that could be used.
Then in order to check if a user has logged in you would need to iterate through the nodes in the XML file(s) and check the details.
2 Comments
Yes, actually in php5 this is very easy to implement. http://devzone.zend.com/article/1713 for example.