Microweber\Utils\Database::escape_string PHP Method

escape_string() public method

Escapes a string from sql injection.
public escape_string ( string | array $value ) : mixed
$value string | array to escape
return mixed Escaped string
    public function escape_string($value)
    {
        if (is_array($value)) {
            foreach ($value as $k => $v) {
                $value[$k] = $this->escape_string($v);
            }
            return $value;
        } else {
            if (!is_string($value)) {
                return $value;
            }
            $str_crc = 'esc' . crc32($value);
            if (isset($this->mw_escaped_strings[$str_crc])) {
                return $this->mw_escaped_strings[$str_crc];
            }
            $search = array('\\', "", "\n", "\r", "'", '"', "");
            $replace = array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z');
            $new = str_replace($search, $replace, $value);
            $this->mw_escaped_strings[$str_crc] = $new;
            return $new;
        }
    }