Make WordPress Core

Opened 10 years ago

Last modified 19 months ago

#31624 new enhancement

$wpdb->prepare() named placeholders

Reported by: ozthegreat's profile ozthegreat Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.2
Component: Database Keywords: needs-unit-tests has-patch
Focuses: Cc:

Description

I think it would be handy to add named placeholders to $wpdb->prepare(). The functionality exists in most modern frameworks and cuts out the need for having to worry about the order of variables, (or repetition) in the current vsprint like syntax.

What I'm proposing is that the second parameter of prepare() can optionally be an associative array where the $key is the named placeholder and the $value is the value associated with it.

This wont affect any existing functionality of prepare() and is fully backwards compatible. If no associative array is passed it will continue to work as always.

Patch with the described functionality is attached for testing.

Attachments (1)

named-placeholders-prepare.diff (1.8 KB) - added by ozthegreat 10 years ago.
->prepare() named placeholders

Download all attachments as: .zip

Change History (5)

@ozthegreat
10 years ago

->prepare() named placeholders

#1 @ozthegreat
10 years ago

That patch doesn't quite work, didn't realise that insert() and delete() pass associative arrays to prepare() by default. This is inconsistent with some of the other methods. Will review and submit an update patch shortly.

#2 @dd32
10 years ago

  • Keywords needs-unit-tests added

This ticket was mentioned in PR #4673 on WordPress/wordpress-develop by @merianos.


19 months ago
#3

  • Keywords has-patch added

…e two new functions required by the new version of the $wpdb->prepare

Trac ticket: 31624

#4 @merianos
19 months ago

As this is my first contribution to the Core, I am working on how to fix the PHPUnit tests that failing.

If any has the time to help, will be more than welcome :)

Note: See TracTickets for help on using tickets.