1

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?

4
  • Yes, it is possible. Inadvisable in many cases, but possible. Commented Aug 18, 2011 at 14:55
  • Why do you have to use xml? Commented 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 . Commented Aug 18, 2011 at 15:24
  • See Apache Xindice, it's a Native XML database server. Commented Aug 18, 2011 at 15:30

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@Marc I'm not going to use this application for big projects. It is very small one.
regardless of size, xml shouldn't be used as a database. If you need a small/compact database, use sqlite. Or something like berkelyDB. They've done all the hard work of allowing concurrent access. You'd have to rebuild everything from the ground up.
0

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

thanks for answer. Then how i can connect with xml file like mysql? is there separate code for this?
You can try using SimpleXML, it was brought in in PHP5 to make XML access easier. w3schools.com/PHP/php_xml_simplexml.asp php.net/manual/en/book.simplexml.php Otherwise, you can try using the XML parser. uk2.php.net/manual/en/book.xml.php
-2

Yes, actually in php5 this is very easy to implement. http://devzone.zend.com/article/1713 for example.

2 Comments

The linked article explains how to read and manipulate XML documents, but does not relate directly to the OP's question, namely, can XML documents be used as a database.
@matt, It's helpful to reach my solution. Thanks:-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.