[wp-trac] [WordPress Trac] #22196: add $wpdb->upsert function

WordPress Trac noreply at wordpress.org
Wed Jul 19 22:41:02 UTC 2017


#22196: add $wpdb->upsert function
-------------------------------------+-----------------------
 Reporter:  thomask                  |       Owner:
     Type:  enhancement              |      Status:  reopened
 Priority:  normal                   |   Milestone:
Component:  Database                 |     Version:  3.4.2
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:
-------------------------------------+-----------------------
Changes (by donpark):

 * keywords:   => has-patch needs-testing
 * status:  closed => reopened
 * resolution:  maybelater =>


Comment:

 Proposed patch adds new method `upsert` to `wp-db.php` and modifies
 private method `_insert_replace_helper`, adding a new `$type` value
 `UPSERT`.

 {{{
 public function upsert( $table, $data, $format = null, $keys = null )
 }}}

 Optional parameter `$keys` is used to filter out keys from `ON DUPLICATE
 KEY UPDATE` part of the query like this:

 {{{
 $wpdb->upsert( 'table', array('id' => 1234, 'column' => 'foo', 'field' =>
 1337 ),
     array('%d', '%s', '%d' ), array( 'id' ) );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/22196#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list