Querying MySQL from an external application
The most important thing here is not to create and destroy the connection as part of executing your query.  Force the calling code to create the connection first (or create it yourself if its not done) but dont destroy the connection until the library is unloaded.  That should improve speed.