Make WordPress Core

Opened 8 years ago

Last modified 4 years 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
Focuses: Cc:


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 8 years ago.
->prepare() named placeholders

Download all attachments as: .zip

Change History (3)

8 years ago

->prepare() named placeholders

#1 @ozthegreat
8 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
8 years ago

  • Keywords needs-unit-tests added
Note: See TracTickets for help on using tickets.