There are a number of situations where you may need to redirect the browser based on the user agent of the browser. An example would be to an IE6 page, or a smartphone modified subdomain.
I'm hooked on using CodeIgniter which uses an active record class. This is bad because when I work on a non CodeIgniter project the work is not done for me. This article explains the PHP function I wrote which takes a Associative array and converts it into a mysql INSERT statement.