WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wpdb->prepare delete example confusion (3 posts)

  1. ivomasterche
    Member
    Posted 1 year ago #

    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 ?

  2. vtxyzzy
    Member
    Posted 1 year ago #

    You are correct. The Codex example appears to be wrong.

    There are other examples here:

    http://codex.wordpress.org/Class_Reference/wpdb#Protect_Queries_Against_SQL_Injection_Attacks

  3. ivomasterche
    Member
    Posted 1 year ago #

    Yes, that was exactly what i thought.

    Should we propose codex correction ?

Topic Closed

This topic has been closed to new replies.

About this Topic