For anyone who needs it, here is a script I wrote to prevent SQL injection. It uses references to the original global arrays to clean them up.
/**
* added the following code to enabled readyness for magic_quotes() being removed
* in PHP6
*
* added by C. Cook 15/8/2008
*/
//Turn off magic quotes the manual way, this also [...]