Firstly, have you considered using SQLite instead of a flat file database.
Next, surely, searching through what you already know of PHP, functions like [man]file/man come to mind?
I mean, you have been around for quite a few months, actively asking questions and such. It is time to think on your own instead of being spoonfed the answers, and then you ask only when you find that you really are stuck.