public function escape($string) {

        // if no active connection exists, return false
        if (!$this->_connected()) return false;

        // if "magic quotes" are on, strip slashes
        if (get_magic_quotes_gpc()) $string = stripslashes($string);

        // escape and return the string
        return mysqli_real_escape_string($this->connection, $string);

    }
public function escape($string) {

        // if no active connection exists, return false
        if (!$this->_connected()) return false;

        // if "magic quotes" are on, strip slashes
        if (get_magic_quotes_gpc()) $string = stripslashes($string);

        // escape and return the string
        return mysqli_real_escape_string($this->connection, $string);

    }
public function escape ( $ string ) { // if no active connection exists, return false if ( ! $ this -> _connected ( ) ) return false ; // if "magic quotes" are on, strip slashes if ( get_magic_quotes_gpc ( ) ) $ string = stripslashes ( $ string ) ; // escape and return the string return mysqli_real_escape_string ( $ this -> connection , $ string ) ; }
Escapes special characters in a string that's to be used in an SQL statement in order to prevent SQL injections.

<i>This method also encloses given string in single quotes!</i>

<i>Works even if {@link http://www.php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc magic_quotes}
is ON.</i>

<code>
// use the method in a query
// THIS IS NOT THE RECOMMENDED METHOD!
$db->query('
SELECT
*
FROM
users
WHERE
gender = "' . $db->escape($gender) . '"
');

// the recommended method
// (variable are automatically escaped this way)
$db->query('
SELECT
*
FROM
users
WHERE
gender = ?
', array($gender));
</code>

@param  string  $string     String to be quoted and escaped.

@return string              Returns the quoted string with special characters escaped in order to prevent SQL
injections.     .
Escapes special characters in a string that s to be used in an SQL statement in order to prevent SQL injections .