Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Do I need to use wpdb prepare before wpdb->insert?

If I am inserting values into a wordpress table using wpdb->insert, do I need to "clean" my data before inserting it or does this method (wpdb->insert) do that for me?

share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted

No, you shouldn't prepare or escape the data, this is done for you by the wpdb class.

From the wpdb class reference:

data:

(array) Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).

If, however, you were writing your own SQL rather than using the insert method, then yes, you should escape using prepare.

share|improve this answer
5  
To add a note: Both insert & update don't need that. But it should be used with query. –  kaiser Aug 15 '11 at 12:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.