Opened 10 years ago
Last modified 19 months ago
#31624 new enhancement
$wpdb->prepare() named placeholders
Reported by: | 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)
Change History (5)
#1
@
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.
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
->prepare() named placeholders