wpdb::_real_escape PHP Method

_real_escape() public method

Real escape, using mysqli_real_escape_string() or mysql_real_escape_string()
See also: mysqli_real_escape_string()
See also: mysql_real_escape_string()
Since: 2.8.0
public _real_escape ( string $string ) : string
$string string to escape
return string escaped
    function _real_escape($string)
    {
        if ($this->dbh) {
            if ($this->use_mysqli) {
                return mysqli_real_escape_string($this->dbh, $string);
            } else {
                return mysql_real_escape_string($string, $this->dbh);
            }
        }
        $class = get_class($this);
        _doing_it_wrong($class, "{$class} must set a database connection for use with escaping.", E_USER_NOTICE);
        return addslashes($string);
    }

Usage Example

 /**
  * Constructor
  *
  * @param  array  $tables Table names as keys, columns as value arrays
  * @param  string $from   String to find, will be escaped.
  * @param  string $replacement     String to use as replacement, will be escaped.
  * @param  wpdb   $wpdb
  */
 public function __construct(array $tables, $from, $replacement, wpdb $wpdb)
 {
     $this->tables = $tables;
     $this->from = $wpdb->_real_escape($from);
     $this->replacement = $wpdb->_real_escape($replacement);
     $this->wpdb = $wpdb;
 }
All Usage Examples Of wpdb::_real_escape