Page 1 of 1

Approach on searching, insertion and deletion in text file

Posted: Sun Sep 03, 2006 12:41 pm
by sendoh07
Hi all. If I have to read from a text file, and do a query to display all usernames. How can I do it from reading a text file? Please note that as much as I would to use MySQL, I am not allowed to. For example, the text file "test.txt" contains the following:

Code: Select all

M0001:jlee:James:Lee:23:Lakers Avenue 111/03 Country:123-345678
M0002:tbogard:Terry:Bogard:23:Lakers Avenue 211/03 Country:124-333678
etc.....
The format is memberID:username:first name:last name:age:address:phone

In normal mysql queries you would just have to do something like "SELECT username FROM Users" to display all the usernames. However, now that I am using just a text file, how can I do searching, insertion and deletion?

Currently, I can only think of tokenizing those data and storing them into an array or linked-list. However, this approach is not that efficient.

Can anyone point me in a right direction please? Thanks!

Posted: Sun Sep 03, 2006 1:18 pm
by feyd
More than likely, you'll need to end up storing the data into an array anyways. There are several conventions for tokening the data. Here are a few:

Posted: Sun Sep 03, 2006 2:25 pm
by jayshields
Why not take a look at some already existing flat-file database systems? A simple Google search will provide you with some, but a known example can be seen here.

Posted: Sun Sep 03, 2006 4:35 pm
by Christopher
I would look into SQLite. It is well supported in PHP, allows SQL queries, and the database is just a file so no server required.

Re: Approach on searching, insertion and deletion in text fi

Posted: Tue Sep 05, 2006 8:33 am
by Yossarian
sendoh07 wrote:Currently, I can only think of tokenizing those data and storing them into an array or linked-list. However, this approach is not that efficient.

Can anyone point me in a right direction please? Thanks!
sqlite would be best I'd say.

However:

I would investigate: getcsv
http://fr2.php.net/manual/en/function.fgetcsv.php
parse_ini_file
http://fr2.php.net/manual/en/function.p ... i-file.php

OR maybe .... serialize objects? ... Ok, its only a suggestion....