Which delete query is better with prepare or delete

Just wondering which of the two delete queries would be the preffered method

$qdel = $wpdb->query($wpdb->prepare("DELETE FROM $shopping_meta_table WHERE meta_shopping_key = '%s' AND wp_user_id = %d", 'product-2', $id));


$qdel = $wpdb->delete($shopping_meta_table,array('meta_shopping_key' => 'product-2', 'wp_user_id'=>$id));

Solutions Collecting From Web of "Which delete query is better with prepare or delete"

By your reputation , It seems that you know about the wordpress very well.

Use of prepare method in query is to make sure we’re not dealing with an illegal operation or any illegal characters.So I recommend you to delete with the prepare method.

Other than that, you might be aware of SQL INJECTION. Before release of wordpress 2.5, there was $wpdb->escape() to prevent SQL Injection whose work was to prevent SQL injection attacks and keeping the bad dudes out. Since WordPress 2.5 a new $wpdb function has been included called ‘prepare’, whose work is to prevent SQL escapes.

So All data in SQL queries must be SQL-escaped before the SQL query is executed to prevent against SQL injection attacks. The prepare method performs this functionality for WordPress, which supports both a sprintf()-like and vsprintf()-like syntax.

Read more about SQL escaping.

Prepare Function.