Jump to content

Using a PHP Variable as a Database


ThePsion5

Recommended Posts

I have an idea...like the topic says, it could be a really good idea or a very poor idea. I thought that since alot of people don't like having to install a database on their servers but want limited database functionality, that it might be possible to implement a pseudo-database using XML. But you can't just store the info in an XML file because then anyone could open it and read your possibly confidential information. So I thought of putting the XML into a PHP variable. Obviously there is one major obstacle for this:How do you update the PHP variable in a way that won't just revert back to the hard-coded values once the server is restarted? I thought about using file functions to write directly to the PHP file containing the variable, but I'm not sure if that would work. Feedback, anyone?

Link to comment
Share on other sites

It's possible to rewrite the php files everytime you update the variables, you just need to set the correct access permissions on the files.But you are creating hurdles you don't need to! What you are effectively talking about is flat files, these used to be all the rage before relational databases. The reason relational databases are now used so commonly is because they are much better at the job.If you really want to use a flat file system I would go back to your xml files. Just place them in a folder without public access, that way a public request for them will be denied but your php scripts (executed on the server) will still be able to access them and do what you want with them.

Link to comment
Share on other sites

It probably is a little bit faster, but I'm finding that for most things I do on the web, speed issues like that don't really matter unless you're doing them in a loop or something. They are still relatively fast. I have a counter on the pages I'm developing that shows me how many SQL queries the page took, and the total execution time from start to end. Even though a page taking either .02 seconds or .2 seconds to execute is an entire order of magnitude higher, in reality the 2 or 3 seconds that it takes to transfer the page through HTTP overshadows anything like that. But like I said, if you are executing a loop 10,000 times or something to process a page, then a little efficiency goes a long way.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...