Jump to content

PHP and non-MySQL databases (or local database files)


tate_etc

Recommended Posts

PHP/MySQL is a perfect combination, but I've been programming for a while, so I'd like to try something new.

 

I'm creating an app, and I'd like it to work as soon as someone uploads it to his/her host. To do this, I need to have a local database file that the app references, because I don't think MySQL, Sybase, or PostgreSQL can help me here (due to admin stuff).

 

My first attempt is to have a DATABASE.DAT file that contains encrypted XML.

 

My app reads the file like this:

 

$database = file_get_contents('database.dat');
$database = my_decoder($database);
$database = new SimpleXMLElement($database);

$user = $database->users->user[0];

 

My app writes to the file like this:

 

$database = $database->asXML();
$database = my_encoder($database);

$handle = fopen('database.dat', 'w');
fwrite($handle, $database);
fclose($handle);

 

The first problem I spotted out almost immediately is:

 

- User 1 can load a page that takes 10 seconds to load

- User 2 can load a page that takes 5 seconds to load

- If User 2 started after and finished before User 1, any changes User 1 makes will overwrite User 2's changes (since User 1 is using the file that was made BEFORE the changes)

 

I guess I could have the app check for changes to the file before writing, but that could get messy.

 

Here are my questions:

 

- Does this even make sense?

- OR can you dynamically change an XML file?

- OR is there another way to include a database with a PHP app?

 

Any input is greatly appreciated!!

Lock files while editing and get a way faster server if its taking that long to load pages.  You could also que certain things like password changes, registrations etc to happen on a cron job so there is a small delay.  To make the software Out-Of-The-Box-Ready, make it run remotely, handling data on your server, giving each app a dynamically generated API key and pre-inserting that into the user's download.

Haha, it doesn't really take that long; I just wanted to use easy numbers, so what I was explaining can make sense. Though it would probably never happen, the thought of someone losing data is very scary.

 

I've thought about having the data hosted remotely. This would be good, since I can keep up with the API keys and monitor any illegitimate activity. The problem is that I don't want to require users to be online while using the app, since developers and others can make use of the app, and I don't want to cause any roadblocks in development (there's already too many).

 

I should also point out that this is my first commercial app. Is there a tutorial or anything to ensure that it's solid and no one can view/edit the code? I've been looking at phpcipher.com, but I really have no idea...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.