in reply to MySQL logic

First, it seems you're lacking some basic understanding of database/sql (e.g., you only have a select query, but you want to bind to a "insert" or an "update"), this really has nothing to do with perl. So I'd suggest do some searching/reading on that, probably before DBI.

Second, it seesm you're doing this in real-time (i.e., while the request comes in), I'd say that's not necessary in general, you could just run a perl script periodically against your access log, which will make your web site faster.