Speaking for Apache 1.3.x, the only way you can share variables accross child processes is through shared memory (shmget() etc). To accomplish this you're going to have to write an Apache module in C. I wrote one a few years ago that used shared memory for tracking some things, if you're having trouble i can dig it out next week.
I don't see much wrong with just reading/incrementing/writing the result to a database though..
If you use an Apache module, you could have more trouble in the future if you want to quickly put your script on other servers etc.
I've got a feeling Apache 2.x can better support "global variables" accross child processes, as i think it uses pthreads instead of fork()ing. I'm not sure though, you'll have to look into it