Mark, that's all fine and dandy, however optimizing your databases through a php script is highly not advised if you have large forums; you're going to lock the tables for the optimization and any users trying to do anything are going to be in a fickle pickle...
Not to mention the PHP Maximum Execution time will eventually be hit if it takes long enough... Not to mention, you can't automate it thought phpmyadmin
...