Support » Fixing WordPress » wpdb->prepare delete example confusion

  • Resolved ivomasterche

    (@ivomasterche)


    Hi,

    I am a little confused with the delete example here

    http://codex.wordpress.org/wpdb_Class#Examples

    It says

    $wpdb->prepare(
    		"DELETE FROM $wpdb->postmeta
    		 WHERE post_id = '13'
    		AND meta_key = 'gargle'
    		"
    	,$id, $key )

    I was wondering whether it’s better to be something like:

    $id = 13;
    $key = "gargle";
    $wpdb->prepare(
    		"DELETE FROM $wpdb->postmeta
    		 WHERE post_id = %d
    		AND meta_key = %s
    		"
    	,$id, $key )

    Actually my question is, if i need to use variables (like $id, $key) i should use %d/%s for placeholders in the query and then put the variables as following parameters in the prepare function right ?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wpdb->prepare delete example confusion’ is closed to new replies.