How do I automatically add data to table periodically?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Jesse B
Forum Newbie
Posts: 7
Joined: Sun Jul 25, 2010 9:44 pm

How do I automatically add data to table periodically?

Post by Jesse B »

I've recently been working on a program to teach myself PHP, and it's grown a bit more than I originally expected it to. Long story short, I'm now working on implementing a search engine. The plan is to simply display the contents of my home server, but I'd like a search to prevent having to scroll through thousands of files.

I've been doing some reading, and realize that I need for there to be a database of the files hosted on the server. I made a mySQL table with the following values:

- Path
- Name
- Extension

I figure that should be adequate for any searches being done. The main thing I need is to figure out how to automatically scan through all files in a given directory, and add the appropriate information to it's corresponding column on the table, all done periodically to keep things somewhat up to date. I've heard of doing a "cronjob" (done some basic reading in to), but I'm not sure how I'd be able to access a table via one of these; they seem like the way to go for adding a schedule however.

My research hasn't been going too well, due mainly to the fact that I don't know the proper terms and jargon to even search properly :P What I'm mainly looking for is just what I should be searching for, any links to beneficial articles, or even any help that you may have to offer.

If you need any more information just lemme know. I hope this is in the proper section, feel free to move it if it is not!

Thanks,


- Jesse
Jesse B
Forum Newbie
Posts: 7
Joined: Sun Jul 25, 2010 9:44 pm

Re: How do I automatically add data to table periodically?

Post by Jesse B »

Alright, well I did make some progress. I managed to write a script to do a recursive scan of the specified directory, and then post the name of the file, the path of the file, and the extension of said file. The ID is also auto-incrementing.

Anyways, I'm not sure how to go about automating this still. Can I set up a cronjob to just run this *.php script that I wrote, or is there more to it than that?

Thanks,


- Jesse
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: How do I automatically add data to table periodically?

Post by superdezign »

Jesse B wrote:Can I set up a cronjob to just run this *.php script that I wrote, or is there more to it than that?
As long as you are on a Unix based server, yeah. That's all there is to it. You may want to place the file in a non-public directory so that people can't access it and cause it to run early.
Jesse B
Forum Newbie
Posts: 7
Joined: Sun Jul 25, 2010 9:44 pm

Re: How do I automatically add data to table periodically?

Post by Jesse B »

Well that's easier than I expected :D Thanks for the help!
Post Reply