First, the proc that caused the error is not included in the posted code.
Secondly, when you connect, you run the code in globalspace, so the database handle is stored in ::mysql_handler, yet atleast in pub:test, you are trying to use the localspace variable mysql_handler. Most likely, you forgot to link the localspace variable to the globalspace one (using the global command).
Same goes for several other variables in your pub:test proc.
The above shows a few working and non-working procs that try to access the globalspace variable ::myvar (set in the beginning of the script):
test1 (works):
Here we access the variable using the full namespace path ::myvar
test2 (not working):
Here we try to access the variable, but we leave out the namespace path. As such, instead we'll end up trying to access the local variable myvar, which does not exist. You'll end up with an error stating "No such variable".
test3 (works):
Here we first use the global command, which will link the local variable myvar to the globalspace variable ::myvar. As a result, whenever we access myvar, we'll actually end up operating on ::myvar.
test4 (works, but generates an error):
Here we first use the upvar command to link the local variable test with the globalspace variable ::myvar. The first putlog will work, as it accesses the now linked variable test. The second putlog will however fail, as there still is no local myvar variable.
test5 (works):
Here we also link test with ::myvar, but it also illustrates how setting a local variable will not affect a globalspace one.