Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File based database?

Status
Not open for further replies.

wrongidea

Programmer
Nov 12, 2001
5
JP
Hi everyone.

My client has a Word document that contains various terms in different languages, and they want an online dictionary, where user can type in a term in whatever language, and get the equivalent in different languages.

Since the site is on an ISP, and they don't support any database interaction, I wanted to utilize some sort of file based database system.

I wanted to create something that is fairly close to an actual database system, using relational structures (there are categories for the terms, and they should be categorized under different languages also).

I vaguely know that there are more than one ways for doing this with PHP, but am not sure which one is most appropriate. There are 35 pages worth of terms in the document, and I want to create something simple and useful.

I wanted to seek some advise because I never had to rely on a file based database system.

Could anyone give me a suggestion on how I should go about achieving this?

Any comments would be greatly appreciated.

Thanks in advance.
 
There are ofcourse multiple ways of solving this.
But you want a flat file db system where you can search in. That is difficult.

First we want to start with creating maps for all different languages.
In those maps we place the categories. And in those categories we have to place the terms. The terms will have to be one of the following two:
1. Make files that represent the word in the filename and put the explanation in that file. (This will give you a fast way to search/find and manage your files/terms, but it will create a lot of files).
2. Make one file and read that out with fopen, parse a rule (which represents the term and the explenation) with fgets. To search in de file you need ereg or str functions. The data will be much more slower read than option one, but managing will only take action on one file.

Maybe the above will help you in your quest ;-)
PS I would prefer the first option for speed. mcvdmvs
-- "It never hurts to help" -- Eek the Cat
 
mcvdmvs,

Thanks for your suggestion.

However, I'm not too sure what you mean by "creating maps"? Could you elaborate on that?

Thanks again.
 
Another idea would be to use a well-formed XML file... I believe PHP has XML functions native. and in the end, it's just a text file. Would be a bit of work typing up the dictionary, if it's very large, but not a big deal...

Anyway, just my $.02

Jhereg
 
You can always use CSV files (Comma separated values).

Afterwards you can read the file and search what you want in an array. I suggest to you to have everything indexed, using binary trees to get to the bottom of your information fast.

class bintree{
var $lower;
var $bigger;
var $obj;

bintree($obj){
$this->obj=$obj;
}

search($obj){
if ($this->obj==$obj) return $this;
elseif ($obj>$this->obj) return search($this->bigger);
else return search($this->lower);
}

}

You can always improve this code.


Anikin
Hugo Alexandre Dias
Web-Programmer
anikin@ip.pt
 
An ISP that doesn't support any DB? Change hosts. MySQL is free, so why wouldn't the host use it? Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
I'd like to thank everyone for their comments.

As far as the ISP is concerned, I'm not in the position to change them. However, they did tell me that they are in the process of setting up MySQL on their server, but god only knows how long that would take.

Besides, it's actually kinda fun to try to figure this out without a database...

I think I'm going to try XML or CVS method and see what I can do...

Thanks again
 
Hi,

So I started creating a XML document. I'm using external entities in my DTD to separate the file (since it's quite big) into different files by categories.

However, I wasn't sure if I should use external entities at all, 'cause if XML parsing function in PHP reads the external files every single time the main file is requested (by fopen/fread) anyway, then it doesn't matter if I have separate files or one big file....or does it? That's only if it does read the external files, and if it doesn't unless specified, then I guess it's ok with the way I'm doing it.

I guess my question is:

Does using external entities improve the performance when reading a big file like this (37 pages in Word)?

If not, I probably should take out the external entities and just make another element in the main XML file that indicates which file to look at??

Any comments/suggestions would be greatly appreciated.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top