This document is brief description of how to create user-defined functions in MySQL using C/C++.  Note that since MySQL now allows for the creation of stored procedures, you may want to go that route first before attempting a C/C++ program.  Click on the following link to view the document: Creating MySQL User-Defined Functions.