Forum Moderators: coopster

Message Too Old, No Replies

Searching in flatfile database

         

vodius

10:05 am on Apr 8, 2003 (gmt 0)

10+ Year Member



I have flatfile database which structure is:
//field1, field2//
In field1 I have value of postal code (canadian A1A1A1)
In field2 I have corresponding email

Now, I'm trying to pass value of postal code and this script should return me value of coresponding email. I have around 700,000 postal codes (yep a lot) and I cannot use database or any plugins for PHP which needs to be installed. It takes about 30 seconds to find that email. I tried usin FFDB [sourceforge.net...] but I don't know what type of file should I use. When I create new database with FFDB it gives me this file which has square symbols in there and a lot of spaces. //Here is how it looks like:/*#  teterine anton  316205%  teterina natalia  382858# machinsky iana  317494*/
It could be just me :-)
If anybody knows a way around this problem please let me know, and guys please keep in mind that I'm not that professional in PHP.
Thanks in advance.

dmorison

10:29 am on Apr 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

Does the Canadian postal code system map nicely to a hierarchical structure?

If so, you could use the filing system on your disk (assuming that you have mkdir permissions) to create yourself an index tree.

For example, the email address for postcode A1A1A1 you would store in the file (for example):

/postcodedb/A1/A1/A1A1A1.txt

also in that directory might be:

/postcodedb/A1/A1/A1A1A2.txt
and
/postcodedb/A1/A1/A1A1A3.txt

wheras the email address for postcode A1A2A1.txt would be in the file:

/postcodedb/A1/A2/A1A2A1.txt

You get the idea.

A lookup is then performed by simply doing an fopen() on the appropriate filename, which you can derive from the postcode you are trying to lookup.

It will certainly be extremely fast.

mavherick

11:17 am on Apr 8, 2003 (gmt 0)

10+ Year Member



Now the only thing you have to worry about is when you run your setup script (like dmorison explained), make sure it's at night or something, that's a lot of calls to mkdir!

But it'll be fast once you're all setup.

If you need info on how to create file / directory, check the File System [php.net] functions in the manual.

mavherick