wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 'bar' ) )
wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
public replace ( string $table, array $data, array | string $format = null ) : integer | false | ||
$table | string | table name |
$data | array | Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). |
$format | array | string | Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. |
return | integer | false | The number of rows affected, or false on error. |
public function replace($table, $data, $format = null)
{
return $this->_insert_replace_helper($table, $data, $format, 'REPLACE');
}
/** * Import forms in bulk. * * @author Jeremy Pry * * @param array $form_data Array of form data, indexed by form ID. * @param bool $replace_existing Whether to replace existing forms. */ public function import_forms($form_data, $replace_existing) { foreach ($form_data as $id => $data) { $existing = $this->get_form($id); if (!$replace_existing && !empty($existing)) { continue; } $data['id'] = $id; $_form_data = $this->prepare_data_for_db($data); $formats = $this->get_format_array($_form_data); $this->wpdb->replace($this->prefixed_table_name, $_form_data, $formats); } }