Zebra_Database::escape PHP Method

escape() public method

This method also encloses given string in single quotes! Works even if {@link http://www.php.net/manual/en/info.configuration.php#ini.magic-quotes-gpc magic_quotes} is ON. 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));
public escape ( string $string ) : string
$string string String to be quoted and escaped. @return string Returns the quoted string with special characters escaped in order to prevent SQL injections. .
return string
    function escape($string)
    {
        // if an active connection exists
        if ($this->_connected()) {
            // 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);
        }
        // upon error, we don't have to report anything as _connected() method already did
        // just return FALSE
        return false;
    }