views:

53

answers:

3

Hello!

I'm coding a website that involves storing very simple data, just a very long list of names with no additional data, on the server. As this data is so simple, I don't really want to use MySQL (it would be a bit too clunky) so I'm asking what's the best way to store very simple data on the server.

I definitely would favour speed over anything else, and easy access to the data via javascript and AJAX would be very good too as the rest of the site is coded in javascript/jQuery. I don't really care if the data can be viewed freely (as it will be available anyway), as long as it can't be changed by unauthorised users.

Thanks,

DLiKS

+2  A: 

Use an XML file that is web-accessible. Then you can query the XML file from the browser if need be, and still parse/write it in PHP. You'll want to use the flock function in PHP to make sure that two instances of a page don't try to write to the file at the same time.

Aaron
Thanks for the answer! Is there any way to access the XML file using Javascript and AJAX?
DLiKS
http://en.wikipedia.org/wiki/XMLHttpRequest
Aaron
+1  A: 

Write it to a file and save the data as a serialized object. This way when you read in the data it's instantly accessible as the variable type you need (array, obj, etc). This will be faster than XML parsing.

Evan
Thanks for the answer! Can you point me to any articles on this method?
DLiKS
Sure: http://php.net/manual/en/function.serialize.php and http://www.php.net/manual/en/function.unserialize.php to read and write the data. Then, if you want to convert the data to json: http://www.php.net/manual/en/function.json-encode.php
Evan
BTW, if you don't need to do any manipulation on the file's information, and literally just want to pass that info to the user, serving up the XML document might be better, because's there is no server processing load then
Evan
+2  A: 

There are a lot of things to think about with this.

  1. Is the information the same for all users with just a single set that applies to all users out there? Or is there a separate set of data for each user?
  2. How is the data going to be served to the client, my guess here is that you would be having a web service or otherwise that might return a JSON.
  3. From a security standpoint, do you want someone to be able to just "grab" the data and run?

Personally I find that a database if often a better choice, but otherwise i would use an XML file. Keep in mind though that you have to be careful with loading/reading of XML files to serve web requests to prevent any potential file locking issues.

Mitchel Sellers
Thanks for the answer! The information would be the same for all users and I don't mind if someone can just take all of the data, it's freely available anyway on the site, as long as they can't edit it!
DLiKS