[wp-trac] [WordPress Trac] #26114: Auto prepare utilities for wp-db.php
WordPress Trac
noreply at wordpress.org
Tue Nov 19 18:04:42 UTC 2013
#26114: Auto prepare utilities for wp-db.php
-----------------------------+------------------------------
Reporter: dougwollison | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Database | Version: trunk
Severity: normal | Resolution:
Keywords: dev-feedback |
-----------------------------+------------------------------
Comment (by nacin):
Andy Skelton and I had a conversation about this a year or two ago, and
it's something we've always wanted to revisit. I think there are a few
other things we need to do first to get to this point, though. But if we
did this, here's how we'd do it:
Rather than ''new'' methods, we can use the existing ones. get_col(),
get_var(), get_row(), and get_results() only accept two arguments: The
query, and the output. We could add a third argument there, or — something
I think is preferred — actually overload the $output argument, instead
allowing an array of prepared values, followed by the $output argument in
position three.
If func_get_arg(1) is an array, then assume it is values to prepare and
that func_get_arg(2) is the $output. Or, if func_get_arg(1) is
ARRAY_N/A/OBJECT/_K, then slice off the first two arguments and let the
function accept additional arguments the same way prepare() currently
does.
There are a number of potential benefits to this. One, you'd always be
preparing a complete query to be executing it, so prepared statements
where bindings happen server-side (like PDO proper or mysqli) could be
used. We could then cache that inside wpdb, thus enabling future queries
with the same signature to be re-executed with new values.
Two, which is more practical and less theoretical, you'd be able to
actually make decisions based on a query's "signature" (a query minus the
prepared values). Example: Filtering all queries of a particular
signature, or invalidating the cache of an entire group of queries.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/26114#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list