Inpsyde\MultilingualPress\Database\WPDBTableStringReplacer::replace_string PHP Method

replace_string() public method

Replaces one string with another all given columns of the given table at once.
Since: 3.0.0
public replace_string ( string $table, array $columns, string $search, string $replacement ) : integer
$table string The name of the table to replace the string in.
$columns array The names of all columns to replace the string in.
$search string The string to replace.
$replacement string The replacment.
return integer The number of affected rows.
    public function replace_string($table, array $columns, $search, $replacement)
    {
        if (preg_match('|[^a-z0-9_]|i', $table)) {
            return 0;
        }
        $replacements = $this->get_replacements_sql($columns, $search, $replacement);
        if (!$replacements) {
            return 0;
        }
        $this->db->query('SET autocommit = 0');
        $affected_rows = (int) $this->db->query("UPDATE {$table} SET {$replacements}");
        $this->db->query('COMMIT');
        $this->db->query('SET autocommit = 1');
        return $affected_rows;
    }