Check out this link
it's poorly named, but should help you get started http://php.about.com/
If you have a hosted environment, you should see a tool called "phpMyAdmin" that lets you connect to your database and run queries.
If MySQL has a stored proc area you want to put that in a stored procedure. When you wanto to run it, call that proc to you page and execute it when it needs to be executed. I think using stored procedures will cut down on web server load unless you are running the sql server along side the web server.