[wp-trac] [WordPress Trac] #11318: $wpdb->prepare() Chokes on LIKE conditions?

WordPress Trac wp-trac at lists.automattic.com
Tue Dec 29 11:07:42 UTC 2009


#11318: $wpdb->prepare() Chokes on LIKE conditions?
--------------------------+-------------------------------------------------
 Reporter:  miqrogroove   |        Owner:  ryan      
     Type:  defect (bug)  |       Status:  closed    
 Priority:  normal        |    Milestone:            
Component:  Database      |      Version:  2.8.4     
 Severity:  normal        |   Resolution:  worksforme
 Keywords:                |  
--------------------------+-------------------------------------------------

Comment(by hakre):

 Regarding the original report:

 {{{
 var_dump($wpdb->prepare("SELECT 1 WHERE col1 LIKE 'image%'"));
 //returns bool(false)
 }}}

 I suggest to use the correct syntax for percentage literals to preserve
 them in the query:

 {{{
 var_dump($wpdb->prepare("SELECT 1 WHERE col1 LIKE 'image%%'"));
 //returns string("SELECT 1 WHERE col1 LIKE 'image%'")
 }}}

 This is the documented behaviour of the
 [http://www.php.net/manual/en/function.sprintf.php#function.sprintf.parameters
 sprintf page].

 The WPDB->prepare() functions documentation as well as the codex would
 benefit from a touchup explaining the user about all three ''format
 specifiers'' it supports: {{{%%}}}, {{{%d}}} and {{{%s}}}.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/11318#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list