Changeset 20287 for trunk/wp-includes/wp-db.php
- Timestamp:
- 03/24/2012 03:24:31 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/wp-db.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/wp-db.php
r19773 r20287 405 405 * 406 406 * @since 2.8.0 407 * @see wpdb:prepare() 408 * @see wpdb:insert() 409 * @see wpdb:update() 407 * @see wpdb::prepare() 408 * @see wpdb::insert() 409 * @see wpdb::update() 410 * @see wpdb::delete() 410 411 * @see wp_set_wpdb_vars() 411 412 * @access public … … 1271 1272 return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) ); 1272 1273 } 1274 1275 /** 1276 * Delete a row in the table 1277 * 1278 * <code> 1279 * wpdb::delete( 'table', array( 'ID' => 1 ) ) 1280 * wpdb::delete( 'table', array( 'ID' => 1 ), array( '%d' ) ) 1281 * wpdb::delete( 'table', array( 'ID' => 1 ), array( '%d' ), 1 ) 1282 * </code> 1283 * 1284 * @since 2.5.0 1285 * @see wpdb::prepare() 1286 * @see wpdb::$field_types 1287 * @see wp_set_wpdb_vars() 1288 * 1289 * @param string $table table name 1290 * @param array $where A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw". 1291 * @param array|string $where_format Optional. An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types. 1292 * @return int|false The number of rows updated, or false on error. 1293 */ 1294 function delete( $table, $where, $where_format = null ) { 1295 if ( ! is_array( $where ) ) 1296 return false; 1297 1298 $bits = $wheres = array(); 1299 1300 $where_formats = $where_format = (array) $where_format; 1301 1302 foreach ( array_keys( $where ) as $field ) { 1303 if ( !empty( $where_format ) ) { 1304 $form = ( $form = array_shift( $where_formats ) ) ? $form : $where_format[0]; 1305 } elseif ( isset( $this->field_types[ $field ] ) ) { 1306 $form = $this->field_types[ $field ]; 1307 } else { 1308 $form = '%s'; 1309 } 1310 1311 $wheres[] = "$field = $form"; 1312 } 1313 1314 $sql = "DELETE FROM $table WHERE " . implode( ' AND ', $wheres ); 1315 return $this->query( $this->prepare( $sql, $where ) ); 1316 } 1317 1273 1318 1274 1319 /**
Note: See TracChangeset
for help on using the changeset viewer.