If you want a 1:1 function mapping, this works, it makes backtraces a bit nasty, but works
class DB
{
public static function escape()
{
$args = func_get_args();
return call_user_func_array('mysql_real_escape_string', $args );
}
}
DB::escape( $foo );
Now I've used the func_get_args / call trick here for one reason only:
This notation should work on any function.
It would however be more optimal to just chain it directly
class DB
{
public static function escape($string)
{
return mysql_real_escape_string( $string );
}
}
And there is no good reason to be stripping slashes, unless you have that horrible "feature" in php enabled which auto-slashes input.
class DB
{
public static function un_gpc($string)
{
if( get_magic_quotes_gpc() === 1 )
{
return stripslashes( $string );
}
return $string;
}
public static function escape($string, $quote=false)
{
if( !$quote )
{
return mysql_real_escape_string( $string );
}
return '"' . self::escape( $string ) . '"';
}
public static function escape_gpc( $string , $quote = false )
{
return self::escape( self::un_gpc( $string ), $quote);
}
public static function get( $string , $quote = true )
{
return self::escape_gpc( $_GET[$string] , $quote );
}
}
# Handy Dandy.
$q = 'SELECT * FROM FOO WHERE BAR = ' . DB::get( 'bar' ) ;