MySQL functions now seem to work. More testing and refinement needed but they do seem to work