Use parameters for field and table names in a MySQL Prepare statement to create truly dynamic SQL
The mysql prepare statement sucks heavy time. You can not (!?!!!) use it to template field and table names. So it is mostly useless for any heavy duty stored procedures that want to address different columns.
Here is a small function that will take care of that :)
-- So now you can in your stored procedures (at last!) do:
The first argument is the template with the question mark '?' as placeholder, the second is a comma separated string with the variables to replace. If you pass too few variables, the remaining placeholders will not be modified so they can be treated with the mysql PREPARE FROM, EXECUTE USING afterwards…
CAVEAT: Hardly tested, do not use in production without really testing this one