Legend, that's got it working!

Now every time I create a new thread I pass the thread ID as the database connection name, and I can have separate MySQL connections per thread.

Thanks very much for the help!