Código PHP:
function sql_quote($value){
if(get_magic_quotes_gpc())
$value = stripslashes($value);
if(function_exists("mysql_real_escape_string"))
$value = mysql_real_escape_string( $value );
else
$value = htmlentities(addslashes( $value ));
return $value;
}