| 1152 | return $this->_insert_replace_helper($table, $data, $format, 'INSERT'); |
| 1153 | } |
| 1154 | |
| 1155 | /** |
| 1156 | * Replace a row into a table. |
| 1157 | * |
| 1158 | * <code> |
| 1159 | * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 'bar' ) ) |
| 1160 | * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) |
| 1161 | * </code> |
| 1162 | * |
| 1163 | * @since 3.0.0 |
| 1164 | * @see wpdb::prepare() |
| 1165 | * @see wpdb::$field_types |
| 1166 | * @see wp_set_wpdb_vars() |
| 1167 | * |
| 1168 | * @param string $table table name |
| 1169 | * @param array $data Data to replace (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). |
| 1170 | * @param array|string $format 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. |
| 1171 | * A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. |
| 1172 | * @return int|false The number of rows inserted, or false on error. |
| 1173 | */ |
| 1174 | function replace( $table, $data, $format = null ) { |
| 1175 | return $this->_insert_replace_helper($table, $data, $format, 'REPLACE'); |
| 1176 | } |
| 1177 | |
| 1178 | /** |
| 1179 | * Private helper function for insert and replace. |
| 1180 | * |
| 1181 | * Runs an insert or replace query based on type |
| 1182 | * |
| 1183 | * @since 3.0.0 |
| 1184 | * @see wpdb::prepare() |
| 1185 | * @access private |
| 1186 | * |
| 1187 | * @param string $table table name |
| 1188 | * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). |
| 1189 | * @param array|string $format 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. |
| 1190 | * A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. |
| 1191 | * @return int|false The number of rows inserted, or false on error. |
| 1192 | */ |
| 1193 | function _insert_replace_helper($table, $data, $format = null, $type = 'INSERT') { |